Giter VIP home page Giter VIP logo

create-a-framework's Introduction

ReadMe for the GROSS module

Description:

The GROSS module is a NPM package that must be required in. Requiring the module provides the functionality to create a HTTP server and handle the routing for 'GET', 'POST', 'PUT' and 'DELETE' requests. The main structure for this module was built using a constructor function and the module as a whole acts similar to the express module.

Requiring in the GROSS module:

var grossModule = require('gross');
var gross = grossModule();

In this example you can see the 'gross' module being required in and set to the variable named 'grossModule'. This variable can now be called and will instantiate all of the functionality of the 'gross' module. A new variable named 'gross' is being used to hold all of that functionality. Now the variable gross can be used to create a server and handle all RESTFUL routing.

Creating a server with the GROSS module:

gross.listen(port, cb);

//Example

gross.listen(3000, function() {
  console.log('Server started on port 3000');
});

The 'gross' module contains the ability to create a server. When calling 'gross.listen' you must also specify the port to listen on as well as a callback function. Console logging the port in which the server has started on is a great use case for this call back as seen in the example.

Routing with the GROSS module:

gross.get(route, cb);
gross.post(route, cb);
gross.put(route, cb);
gross.delete(route, cb);
gross.route();
//Examples for how to use the "GET" and "DELETE" routes.

gross.get('/data', function(request, response) {
  res.end();
});

gross.post('/data', function(request, response) {
  request.on('data', (data) => {
    // Do something with data.
    res.end();
  });
});

// This is how the 'GROSS' module handles requests and sends them to the right route.
gross.route = function() {
  return (req, res) => {
    var routeFunction = this.routes[req.method][req.url];
    routeFunction(req, res);
  };
};

The 'gross' module can handle "GET", "POST", "PUT", and "DELETE" routes. It controls these routes by first sending all request through the route function. The final example shows how this route function works. It will take in whichever route is hit, interpret the request method and request URL and then use this information to form a function that will handle the request.

create-a-framework's People

Contributors

sgruse avatar

Watchers

 avatar

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.