Skip to content

ssr1ram/synthify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SYNTHIFY

A minimalist component-ized way of automating an api and routes within an expressjs node app.

Dependencies

$ npm install yo -g
$ npm install gulp -g

Install

$ npm install synthify

Yeoman generator

The easiest way to get started is to generate an app using the generator-synthify module see: http://github.com/ssr1ram/generator-synthify

$ npm install -g generator-synthify
$ mkdir myproject
$ cd myproject
$ yo synthify

Example Usage

var express = require('express');
var synthify = require('synthify')

var app = express();

var synthoptions = {
};

synthify.doapi(app, synthoptions);
synthify.doroutes(app, synthoptions);

app.set('views', __dirname + '/pages');

var server = app.listen(3000, function() {
        console.log('Listening on port %d', server.address().port);
});

api

Base directory structure

api/
   foo/
       getIndex.js

You can then declare a request handler for a specific HTTP method in any file that is in the resources directory by assigning a function to exports.<optional: ActionName>.

Possible function names:

exports.get:
    Creates a get method that will expect the resources ID.
    It will handle a request of this form, for example: /api/memoes/124
exports.getIndex:
    Special version of get that won't expect a resource ID.
    e.g. GET /api/memoes. Use this for getting a list of resources.
exports.post:
    Handles post requests, does not expect a resource ID.
    e.g. POST /api/memoes. Use this for created new resources.
exports.put:
    Similar to exports.get but will respond to requests using the put method.
    Use this for making changes to the specified resource.
exports.delete:
    Similar to exports.get but will respond to requests using the delete method.
    Use this to delete the specified resource.
exports.getAnything_else:
    Create custom actions for a resource by using one of the four methods
    followed by a custom name. e.g.
    exports.postPublish responds to POST /api/memoes/publish?id=124.

pages

base directory structure

pages/
    bar.jade
    defaults/
        layout.jade
    foo/
        foo.jade
        foo_front.coffee
        route.coffee
    index.jade
    pages.coffee
    route.coffee

special file names

  • foo_front.js or foo_front.coffee is the entry browserify file used by gulp and the resulting file is placed in public/js/..(relative path)/foo.js (and foo.min.js)
  • route.coffee is used by synthify to set routes
  • foo.less and foo.css files are processed by gulp and resulting files placed in public/css/..(relative path)/foo.css

synthify api

pages.coffee having

synthify = require('synthify')

getIndex = (req, res) ->
    res.render("index.jade")

getFoo = (req, res) ->
    synthify.apiPreload(req, res, "/api/foo", (data) ->
        res.render("foo/foo.jade", {preloadData: data})
    )

getBar = (req, res) ->
    res.render("bar.jade")

License

MIT

Credit

  • Original Creators
  • This project was inspired by synthjs created by Jon Abrams (Twitter | GitHub).

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published