Giter Club home page Giter Club logo

egg-mongodb-example's Introduction

egg-mongodb-example

a example of eggjs, mongodb, restful api and other stuff made it work...

Examples for 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
$ 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

{
"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

{
"meta":{"total":1},
"data":[
{"_id":"58d8a899f5f2486f1f6d4236","uid":1,"name":"admin","pass":"123","status":1,"time":"1325472736"}
]
}

api/users/2 PUT Update data with uid

{"name":"admin123","pass":"123","status":1,"time":"1325472736"}

api/users POST insert data

{"name":"admin123","pass":"123","status":1,"time":"1325472736"}

same with news and news_type for rest api data.

egg-mongodb-example's People

Contributors

fomenyesu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

egg-mongodb-example's Issues

POST, "error": "Cannot read property 'uid' of null"

POST /api/users/ HTTP/1.1
Host: localhost:7001
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 971a5a87-55c5-6f79-d755-e8ce9a9aa309

{"uid":2,"name":"admin123","pass":"123","status":1,"time":"1325472736"}

response:

{
"error": "Cannot read property 'uid' of null"
}

增加user的方法运行失败

在README中:
api/users POST insert data

{"name":"admin123","pass":"123","status":1,"time":"1325472736"}

参照此,使用postman
image
image
测试接口失败,失败原因:
image

请问是什么原因呢?测试两个get方法都可以运行的,而且我也看过旧issue,IdGenerator表也建起来了,求大神们解答一下~

MIME type ('text/html') is not a supported stylesheet MIME type

大佬你好!
下载你的项目后运行报错:

Refused to apply style from 'http://localhost:7001/index.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

刚学习eggjs,不知道是不是什么地方配置的不对呀,感谢感谢!

几点 review 建议

  • run 目录要配置下 .gitignore,这个是运行时的数据
  • 建议用 egg-init --type=simple . 来初始化项目
  • "egg-view-react": "^0.0.1", 没用到不用引入
  • config 里面有很多没用到的可以删掉

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.