# koa-rest-mongoose

> mongoose rest generator for koa

Latest version **2.0.3** (published 2017-05-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install koa-rest-mongoose
pnpm add koa-rest-mongoose
yarn add koa-rest-mongoose
bun add koa-rest-mongoose
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.3 |
| Published | 2017-05-25 |
| First published | 2016-08-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 4.0.0 |
| Dependencies | 5 |
| Known vulnerabilities | 0 (+7 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 13 |
| Author | luoyjx |
| Maintainers | luoyjx |
| Keywords | koa, rest, mongoose, api |

## Links

- npm: https://www.npmjs.com/package/koa-rest-mongoose
- Repository: https://github.com/luoyjx/koa-rest-mongoose
- Homepage: https://github.com/luoyjx/koa-rest-mongoose#readme
- Issues: https://github.com/luoyjx/koa-rest-mongoose/issues
- npm.io page: https://npm.io/package/koa-rest-mongoose

## Dependencies (5)

- [debug](https://npm.io/package/debug.md) ^2.6.8
- [co-body](https://npm.io/package/co-body.md) ^5.1.1
- [bluebird](https://npm.io/package/bluebird.md) ^3.5.0
- [mongoose](https://npm.io/package/mongoose.md) ^4.5.10
- [koa-router](https://npm.io/package/koa-router.md) ^5.4.0

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 2.0.3 (latest) — 2017-05-25
- 2.0.1 — 2017-05-24
- 2.0.0 — 2017-05-24
- 1.0.3 — 2016-08-31
- 1.0.2 — 2016-08-30
- 1.0.1 — 2016-08-30
- 1.0.0 — 2016-08-30

## README

# koa-rest-mongoose 

[![npm](https://img.shields.io/npm/v/koa-rest-mongoose.svg)](https://www.npmjs.com/package/koa-rest-mongoose) [![Build Status](https://travis-ci.org/luoyjx/koa-rest-mongoose.svg?branch=master)](https://travis-ci.org/luoyjx/koa-rest-mongoose)

mongoose rest generator for koa1

[![NPM](https://nodei.co/npm/koa-rest-mongoose.png?downloads=true)](https://nodei.co/npm/koa-rest-mongoose/)

# Installation

```shell
npm install koa-rest-mongoose
```

# Usage

```javascript
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 |
| ------------- | ------------- | --------------- |
| GET           | Get all documents, or documents that match the query. <br> You can use [mongoose find conditions] (http://mongoosejs.com/docs/queries.html), limit, skip and sort. <br> For example: <br> **/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. |

---
_Source: https://npm.io/package/koa-rest-mongoose · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
