课程将做什么
为一个虚拟的汽车经销商网站,开发一个 JSON-based 的 API
不会专注前端到后端,本教程只专注后端。
先决条件
至少熟悉
- Node/Express
 - Javascript/ES2015
 
技术
- Node(v 7.6.0 and up)
 - ExpressJS
- Mongoose
 
 
Models
User
- firstName
 - lastName
 - a cars array of cars
 
Cars
- make
 - model
- year
 - seller
 
 
API endpoints
Users
| 方法 | 路径 | 描述 | 
|---|---|---|
| GET | /users | lists all users | 
| POST | /users | creates a new user | 
| GET | /users/:id | lists particular user | 
| PUT | /users/:id | updates(by replacing) | 
| PATCH | /users/:id | updates(by patching fields) | 
| DELETE | /users/:id | delete | 
| GET | /users/:id/cars | 列出用户销售的车 | 
| POST | /users/:id/cars | 新建用户销售骑车 | 
Cars
| 方法 | 路径 | 描述 | 
|---|---|---|
| GET | /cars | lists all cars | 
| POST | /cars | creates a new car | 
| GET | /cars/:id | lists particular car | 
| PUT | /cars/:id | updates(by replacing) | 
| PATCH | /cars/:id | updates(by patching fields) | 
| DELETE | /cars/:id | delete |