Code Monkey home page Code Monkey logo

node-rest-api-without-express's Introduction

Requirements
~~~~~~~~~~~~

1. Node.js v10.5.0
2. MongoDB v3.6

How to run
~~~~~~~~~~

1. Make sure mongodb server is running.
2. Goto application code directory and run npm install.
3. Modify the connection string config.js
4. Run "node index.js"

Project Structure
~~~~~~~~~~~~~~~~~

1. index.js - Bootstraps the application
2. config.js - Database and other configurations
3. router.js - Custom router for routing endpoints
4. routes.js - List of routes (api endpoints in the project)
5. common - Some common functions/helpers that are used throught the project.
6. models - Project's models
7. controllers - Project's controllers

Request Requirements
~~~~~~~~~~~~~~~~~~~~

1. API is JSON based
2. All requests should have 'Content-Type: application/json' header set
3. Request body for POST and PUT should be in JSON format.

Models
~~~~~~
(I have assumed manager and employee as same entity and distinguished them with 'isManager' property)
Employee:
{
    name: ""                // Name of the employee,
    email: ""               // Email of the employee
    isManager: true/false   // If the employee is a manager or not
    peers: []               // Array of employee who have this employee as manager
    managerId: ""           // If of this employee's manager
}

Project:
{
    name: ""                // Name of the project,
    employeeIds: []         // Array of employees who are part of this project
    managerId: ""           // Id of this project's manager
}

Example Requests and Responses
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

GET localhost:3000/employee
Response:
{
    "status": "success",
    "data": [
        {
            "_id": "5b35af170177f90fd68fedd9",
            "name": "Shalu Singhal",
            "email": "[email protected]"
        },
        {
            "_id": "5b366b7e38acd914fa966289",
            "name": "John Doe",
            "email": "[email protected]"
        },
        {
            "_id": "5b366eb23259a415335f80c2",
            "name": "Ram Dev",
            "email": "[email protected]"
        }
    ]
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

POST localhost:3000/employee
Body:
{
    "name": "Garry Tan",
    "email": "[email protected]",
	"manager": "5b35af170177f90fd68fedd9",
	"peers": [ "5b370dfb1cf2c415cfe9c62a" ],
	"isManager": true
}

Response:
{
    "status": "success",
    "data": {
        "_id": "5b3743f3afcb981bf0958e97",
        "isManager": false,
        "name": "Garry Tan",
        "email": "[email protected]",
        "managerId": "5b35af170177f90fd68fedd9",
        "peers": [ "5b370dfb1cf2c415cfe9c62a" ]
    }
}

Note: I have kept the project simple so that you get idea of my programming capabilities. This just a proof of concept and is in no way
a good ready to use REST API.

node-rest-api-without-express's People

Contributors

neerajpurespectrum avatar shalusinghal 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.