Giter VIP home page Giter VIP logo

node-rest's Introduction

Simple Node REST API

This is a simple Node JSON REST API (No external module, No external framework) app app build to function as expected. The purpose is just to create a prototype to right a simple rest API in node, more coming.

Start

node index.js

Test

Send a get request to /hello you will get a response related to this: { "message": "Hi, how're you doing?" }

Use

To use this API application, you can add more to the handlers configuration in the index.js file.

Example

// Define your handler function
handlers.time =  (data = null, callback) => {
        callback(200, {
            'message': new Date()
        })

// Register the route in the router object
router.time = handlers.time

Test your handler

curl "http://localhost:3000/time"

Sample response

{ "message": "Wed Aug 29 2018 09:52:40 GMT+0100 (West Africa Standard Time)" }

HTTPS Configuration

Note, for the purpose of the application, I have generated an HTTPS cert.pem and key.pem files in order to make the HTTPS version work. However, in realtime production server, this 2 files should not be publicly revealed.

If you also wish you generate these SSL cert for development, you can follow this steps: Generating a self-signed certificate using OpenSSL

node-rest's People

Watchers

James Cloos 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.