2.0.3 • Published 7 years ago

koa-rest-mongoose v2.0.3

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

koa-rest-mongoose

npm Build Status

mongoose rest generator for koa1

NPM

Installation

npm install koa-rest-mongoose

Usage

const koa = require('koa');
const mongoose = require('mongoose');
const KoaRestMongoose = require('koa-rest-mongoose');

// 1 step, mongoose
const mongoUrl = '127.0.0.1:27017/koa_rest_mongoose';
const schema = new mongoose.Schema({
  email: String,
  name: String,
  password: String,
  address: String,
  zipcode: Number,
  lists: Array
});

mongoose.connect(mongoUrl);
mongoose.model('user', schema);

// 2 step, koa and router
const app = koa();
const rest = KoaRestMongoose({
  prefix: '/api'
});
app.use(rest.routes());

// 3 step, done
app.listen(process.env.PORT || 5000);

TODO feature

  • middlewares support

API

Following REST API is now created for you:

HTTP Verb/users/users/:id
GETGet all documents, or documents that match the query. You can use mongoose find conditions, limit, skip and sort. For example: /api/users?conditions={"name":"john"}&limit=10&skip=1&sort=-zipcodeGet the addressed document.
POSTCreate a new document and send it back.Update the addressed document with specified attributes.
PUTCreate a new document and send it back.Replace the addressed document.
DELETEn/aDelete the addressed document.
PATCHn/aUpdate the addressed document with specified attributes.
2.0.3

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago