Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fomenyesu/egg-mongodb-example
a example of eggjs, mongodb, restful api and other stuff made it work...
https://github.com/fomenyesu/egg-mongodb-example
egg-mongodb egg-plugin eggjs-example eggjs-mongodb-example
Last synced: about 1 month ago
JSON representation
a example of eggjs, mongodb, restful api and other stuff made it work...
- Host: GitHub
- URL: https://github.com/fomenyesu/egg-mongodb-example
- Owner: fomenyesu
- Created: 2017-04-07T08:54:15.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-02-18T14:55:11.000Z (almost 5 years ago)
- Last Synced: 2024-08-01T18:31:33.276Z (4 months ago)
- Topics: egg-mongodb, egg-plugin, eggjs-example, eggjs-mongodb-example
- Language: JavaScript
- Size: 433 KB
- Stars: 124
- Watchers: 14
- Forks: 34
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-egg - egg-mongodb-example - a example of eggjs, mongodb, restful api and other stuff made it work... ![](https://img.shields.io/github/stars/fomenyesu/egg-mongodb-example.svg?style=social&label=Star) (应用 / 插件)
- awesome-egg - egg-mongodb-example - a example of eggjs, mongodb, restful api and other stuff made it work... (Applications)
README
# egg-mongodb-example
a example of eggjs, mongodb, restful api and other stuff made it work...# Examples for [egg](https://github.com/eggjs/egg/)
## Usage
make sure you nodejs version >7.0
install mongodb
start mongodb
import data.json to mongodb
1. create Collection: "web_admin" "web_news" "web_newsType" "IdGenerator"
2. create Documents in data.json
run npm to start server
npm start```bash
$ npm install
$ npm start
```## REST API Example
Follow the naming conventions of rails:
method | url | file path | controller name
--- | --- | --- | ---
**GET** | `/api/{objects}[?per_page={per_page}&page={page}]` | `app/controller/{objects}.js` | **index()**
**GET** | `/api/{objects}/:id` | `app/controller/{objects}.js` | **show()**
**POST** | `/api/{objects}` | `app/controller/{objects}.js` | **create()**
**PUT** | `/api/{objects}/:id` | `app/controller/{objects}.js` | **update()**
**DELETE** | `/api/{objects}/:id[s]` | `app/controller/{objects}.js` | **destroy()**api/users GET List
```javascript
{
"meta":{"total":3},
"data":[
{"_id":"58d8a899f5f2486f1f6d4236","uid":1,"name":"admin","pass":"123","status":1,"time":"1325472736"},
{"_id":"58db7828a14b14815447cf33","name":"sdf","pass":"123","status":1,"time":"1325472736","uid":3,"__v":0},
{"_id":"58db7d3bcee4d48df6f5bdfd","name":"sdddf","pass":"123","status":1,"time":"1325472736","uid":4,"__v":0}
]
}
```api/users/1 GET Single Data
```javascript
{
"meta":{"total":1},
"data":[
{"_id":"58d8a899f5f2486f1f6d4236","uid":1,"name":"admin","pass":"123","status":1,"time":"1325472736"}
]
}
```api/users/2 PUT Update data with uid
```javascript
{"name":"admin123","pass":"123","status":1,"time":"1325472736"}
```api/users POST insert data
```javascript
{"name":"admin123","pass":"123","status":1,"time":"1325472736"}
```same with news and news_type for rest api data.