• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

t3chnoboy/koa-mongo-rest: Rest API generation for Koa

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

t3chnoboy/koa-mongo-rest

开源软件地址:

https://github.com/t3chnoboy/koa-mongo-rest

开源编程语言:

JavaScript 46.6%

开源软件介绍:

Koa mongo REST NPM version Dependency Status Build Status

Easy REST api for koa server

NPM

Installation

Install using npm:

npm install koa-mongo-rest

Usage

Require library

generateApi = require('koa-mongo-rest');

Create mongoose model

mongoUrl = '127.0.0.1:27017';
mongoose = require('mongoose');
mongoose.connect(mongoUrl);

schema = new mongoose.Schema({
  email: String,
  name: String,
  password: String,
  address: String,
  zipcode: Number,
  lists: Array
});

model = mongoose.model('users', schema);

Create server

var koa = require('koa');
var router = require('koa-router');

var app = koa();

//router is required
app.use(router(app));


//add REST routes to your app. Prefix is optional
generateApi(app, model, '/api');

app.listen(process.env.PORT || 5000);

Following REST API is now created for you:

HTTP Verb /users /users/:id
GET Get all documents, or documents that match the query.
You can use [mongoose find conditions] (http://mongoosejs.com/docs/queries.html), limit, skip and sort.
For example:
/api/users?conditions={"name":"john"}&limit=10&skip=1&sort=-zipcode
Get the addressed document.
POST Create a new document and send it back. Update the addressed document with specified attributes.
PUT Create a new document and send it back. Replace the addressed document.
DELETE n/a Delete the addressed document.
PATCH n/a Update the addressed document with specified attributes.



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
JustGreenHand/koa-app: koa实践发布时间:2022-06-24
下一篇:
minghe/generator-k: koa工程生成器发布时间:2022-06-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap