Giter Club home page Giter Club logo

catalysis's Introduction

Currently under construction

Catalysis.js

Install

$ npm install -g catalysis-init

Create Project

enter the directory where you want your project to be located and write command:

$ catalysis-init new example-project

Features

  • Controller
  • Model
  • Service
  • Middleware
  • WebSocket
  • Dependency Injection
  • Routing
  • REST API
  • Static file serving
  • Template Engine
  • Multipart support
  • Cache
  • Email
  • Validation
  • Markdown
  • Plugin

Introduction

Here is an example of how to write a hello world application. Let's get started!

We first create a file named HelloController.js within folder api/controllers/ and here we define the Controller with an Action named hello:

module.exports = {
  hello: (req, res) => {
    res.end("Hello world!");
  }
}

After controller has been defined, then we have to define a route in order to routing requests to the action. Let's edit the Configuration config/setting.js:

module.exports = {
  ...
  actions: [
    { method: "GET", url: "/", action: "HelloController.hello" }
  ]
  ...
}

That's it! Let's enter the command and run:

$ node app

Open browser and type the url "localhost:80", then you should see "Hello world!" in the page.

Controllers

Overview

Controllers (the C in MVC) are the objects in your Catalysis application that are responsible for responding to requests from a web browser, mobile application or any other system capable of communicating with a server. They often act as a middleman between your services and views.

Actions

Controllers are comprised of a set of methods called actions. Actions are bound to routes in your application, so that when a client requests the route, the action is executed to perorm some bussiness logic and send a response. For example the GET /hello route in your application cound be bound to an action like:

module.exports = {
  ...
  hello: function(req, res) {
    res.end("Hi there!");
  }
  ...
}

Any time a web browser is pointed to /hello URL on your app's server, the page will display the message: "Hi there!".

Where are controllers defined?

Controllers are defined in the api/controllers/ folder. By convention, Catalysis controllers are usually Pascal-cased, so that every word in the filename (including the first word) is capitalized: for example, UserController.js, MyController.js and SomeGreatBigController.js are all valid, Pascal-cased names.

What does a controller file look like?

A controller file defines a JavaScript dictionary (aka "plain object") whose keys are action names, and whose values are the corresponding action method. Here's a simple example of a full controller file:

module.exports = {
  hi: function(req, res) {
    res.end("Hi there!");
  },
  byte: function(req, res) {
    res.redirect("http://www.example.com");
  }
}

This controller defines two actions: hi and byte. The hi action responds to request with a string message, while the bye action responds by redirecting to another web site.

catalysis's People

Contributors

magicweirdo avatar

Stargazers

CarrotKey avatar  avatar

Watchers

James Cloos avatar  avatar CarrotKey avatar

catalysis's Issues

Use template-literal instead of EJS

Template Literal is fastest, smallest and simplest template engine, because it use JS's literal template feature.

It's 55 times faster than EJS, and it also use less CPU and RAM ressources, so it may be a good idea to use it instead of EJS ๐Ÿ˜€

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.