项目作者: br1code

项目描述 :
Ready-to-use REST API implemented in Node.js and MongoDB
高级语言: JavaScript
项目地址: git://github.com/br1code/node-rest-api.git
创建时间: 2018-12-11T04:41:21Z
项目社区:https://github.com/br1code/node-rest-api

开源协议:

下载


Node Rest API

Available routes:

Replace the word ‘models’ with your model name

Action Route Function
GET /models getAll()
POST /models create()
GET /models/:id getOne(id)
PUT /models/:id update(id, model)
DELETE /models/:id remove(id)

In order to add a new entity to use with the API, you need to create a new MongoDB Model

  1. // Model example
  2. // Path directory -> /models
  3. 'use strict';
  4. const mongoose = require('mongoose');
  5. let postSchema = new mongoose.Schema({
  6. body: String,
  7. title: String,
  8. author: String
  9. });
  10. let postModel = mongoose.model('Post', postSchema);
  11. module.exports = postModel;

Then you need to register the routes of your new model

  1. // Path directory -> /routes/routesConfig.js
  2. // Add your new route here
  3. const routes = [
  4. // createRoutes(Route Name '/posts', Model Name 'post')
  5. createRoutes('posts', 'post')
  6. ];

Your API is ready to use. Just run:

  1. node server.js