# koa-mongo-rest

> generate REST API with koa and mongo

Latest version **0.3.4** (published 2015-05-30) · BSD-2-Clause license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: insecure dependencies; abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.4 |
| Published | 2015-05-30 |
| First published | 2014-01-01 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+7 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 61 |
| Author | Dmitry Mazuro |
| Maintainers | t3chnoboy, tomaash, mgenev |
| Keywords | koa, REST, API, mongo, mongodb, mongoose, es6, generators, database, db |

## Links

- npm: https://www.npmjs.com/package/koa-mongo-rest
- Repository: https://github.com/t3chnoboy/koa-mongo-rest
- Issues: https://github.com/t3chnoboy/koa-mongo-rest/issues
- npm.io page: https://npm.io/package/koa-mongo-rest

## Dependencies (3)

- [mongoose](https://npm.io/package/mongoose.md) ^4.0.2
- [pluralize](https://npm.io/package/pluralize.md) 1.1.2
- [koa-body-parser](https://npm.io/package/koa-body-parser.md) git://github.com/tomaash/koa-body-parser.git

## 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

- 0.3.4 (latest) — 2015-05-30
- 0.3.3 — 2015-05-28
- 0.3.2 — 2015-05-27
- 0.3.1 — 2015-05-09
- 0.3.0 — 2015-05-08
- 0.2.0 — 2014-03-31
- 0.1.2 — 2014-03-30
- 0.1.1 — 2014-03-30
- 0.1.0 — 2014-03-30
- 0.0.4 — 2014-02-20
- 0.0.3 — 2014-01-23
- 0.0.2 — 2014-01-01

## README

# Koa mongo REST [![NPM version](https://badge.fury.io/js/koa-mongo-rest.svg)](http://badge.fury.io/js/koa-mongo-rest) [![Dependency Status](https://gemnasium.com/t3chnoboy/koa-mongo-rest.svg)](https://gemnasium.com/t3chnoboy/koa-mongo-rest) [![Build Status](https://travis-ci.org/t3chnoboy/koa-mongo-rest.svg?branch=master)](https://travis-ci.org/t3chnoboy/koa-mongo-rest)

Easy REST api for [koa](http://koajs.com) server  

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



## Installation
Install using npm:
```sh
npm install koa-mongo-rest
```

## Usage

Require library
```javascript
generateApi = require('koa-mongo-rest');
```

Create mongoose model
```javascript
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
```javascript
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. <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-mongo-rest · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
