willie-b / node-rest-api-without-express Goto Github PK
View Code? Open in Web Editor NEWThis project forked from shalusinghal/node-rest-api-without-express
REST API implementation in node.js without using express
This project forked from shalusinghal/node-rest-api-without-express
REST API implementation in node.js without using express
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.