Git Product home page Git Product logo

nodejs-rest-api-example's Introduction

NodeJS secure RESTFUL api

A minimal, secure RESTFUL api for NodeJS. This project includes user login, access control of objects, and encrypted hashing of passwords right out of the box! Just delete the example model, add your own, and run!

Installation

  • Clone the repo by using git clone.
  • Run npm install on the cloned directory.
  • Edit the private/config.js file to suit your needs.
  • Add APIs using the instructions below to suit your needs.

Steps to add new API

  • Copy the template model (models/Recipe.js) to a new file in the models folder and make the modifications outlined in the header.

copy models/Recipe.js --> models/Custom.js

  • Copy the template controller (controllers/RecipeController.js) to a new file in the controllers folder and make the modifications outlined in the header.

copy controllers/RecipeController.js --> controllers/CustomController.js

  • Import your controller in app.js underneath the existing controllers, like so:
var recipeController = require('./controllers/RecipeController');
var customController = require('./controllers/CustomController');
  • Add the routing line to app.js underneath the existing routes, like so:
app.use('/api', recipeController);
app.use('/api', customController);

Running the software

  • node app.js for simple setups.
  • I would recommend looking at the pm2 module for running on a production server.

Creating users

To create users, simply send a GET to /user/create with the required fields in the query string, like so:

http://localhost:3000/user/create?username=hello&password=world

API Endpoints

GET http://localhost:3000/api/recipe/list
GET http://localhost:3000/api/recipe/create?foo=hello&bar=world // creates object with fields foo=hello, bar=world
GET http://localhost:3000/api/recipe/get/:id // gets object with Mongo id ":id"
GET http://localhost:3000/api/update/get/:id?foo=hello&bar=world // updates object with Mongo id ":id" and fields foo=hello, bar=world
GET http://localhost:3000/api/recipe/delete/:id // deletes object with Mongo id ":id"

nodejs-rest-api-example's People

Contributors

claymcleod 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.