Node.js library/framework that simplifies and improves HTTP resource creation, API endpoint routing, and error handling.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

README.md

crookse.Node

Node.js library/framework that simplifies and improves HTTP resource creation, API endpoint routing, and error handling.

crookse.Node npm version

// Require the package
var CrookseNode = require('crookse-node');

// Create and run the server (listens at localhost:1337 by default)
var server = CrookseNode.createServer('Server-1');
server.run();

// Add an HTTP resource that can be retrieved from the / URI
server.addHttpResources([
  {
    paths: ['/'],
    class: function HomeResource() {
      // localhost:1337
      this.HTTP_GET_JSON = () => { this.response.end(JSON.stringify({message: "You made a GET request and received a JSON response!"})); };
      // localhost:1337
      this.HTTP_POST_JSON = () => { this.response.end(JSON.stringify({message: "You made a POST request and received a JSON response!"})); };
      // localhost:1337?output=html
      this.HTTP_GET_HTML = () => { this.response.end('<p>Message:</p><p>You made a GET request and received an HTML response!</p>'); };
      // localhost:1337?output=xml
      this.HTTP_GET_XML = () => { this.response.end('<response><body><message>You made a GET request and received an XML response!</message></body></response>'); };
    }
  }
]);

Features

Installation

$ cd /path/to/your/project
$ npm install --save crookse-node

Documentation Pages

License

MIT


Thanks StackEdit and Shields.io.