1.1.1 • Published 8 years ago

luc-basic-routing v1.1.1

Weekly downloads
4
License
ISC
Repository
github
Last release
8 years ago

HTTP-Framework

To install npm package: npm i luc-basic-routing

Summary

This simple HTTP framework will handle routing for all REST methods. This package will do basic routing for on a http server.

Setup

To initialize the server and the necessary modules, first create a JS file in the root and put in:

'use strict'
var customModule = require('luc-basic-routing');
var router = customModule();

You can name var router anything you want, but you have to keep the naming convention consistent. In my example I'll make a route to /projects. To make a POST request you would:

router.post('/projects', (req, res) => {
  req.on('data', (data) => {
    //run code here
    res.end();
  })
})

Similarly if you wanted to make GET requests, you would do:

router.get('/projects', (req, res) => {
  req.on('data', (data) => {
    //run code here
    res.end();
  })
})

Once you have all your methods set up you need to get your server started. You need to insert a few lines of code in whereever you require in the server module file to invoke the server function. for example:

  router.listen(3000, () => {
    console.log('server started');
  })

Lastly these routes to a data directory that isn't included with the package. Make sure to make a directory in the root named 'data'. More sample requests are also listed in the test directory for more reference material.

1.1.1

8 years ago

1.1.0

8 years ago