官方网站:github.com/typicode/js…
终端输入:sudo npm install -g json-server
创建一个json文件
{
"user": [
{
"id": 1,
"name": "james",
"phone": "333-444-555",
"email": "james@sina.com",
"age": 30,
"companyid": 1
},
{
"id": 2,
"name": "curry",
"phone": "333-444-555",
"email": "curry@sina.com",
"age": 31,
"companyid": 2
},
{
"id": 3,
"name": "davis",
"phone": "333-444-555",
"email": "davis@sina.com",
"age": 3,
"companyid": 3
},
{
"id": 4,
"name": "jackson",
"phone": "333-444-555",
"email": "jackson@sina.com",
"age": 33,
"companyid": 3
},
{
"name": "bryant",
"phone": "333-444-555",
"email": "bryant@sina.com",
"age": 41,
"companyid": 4,
"id": 5
}
],
"company": [
{
"id": 1,
"companyname": "apple",
"des": "apple is good"
},
{
"id": 2,
"companyname": "huawei",
"des": "huawei is good"
},
{
"id": 3,
"companyname": "oppo",
"des": "oppo is good"
},
{
"id": 4,
"companyname": "alibaba",
"des": "alibaba is good"
}
]
}
get请求
json-server --watch db.json
http://localhost:3000/user
http://localhost:3000/user/1
http://localhost:3000/company/
http://localhost:3000/company/1
http://localhost:3000/company?companyname=apple
http://localhost:3000/company?companyname=apple&companyname=alibaba
http://localhost:3000/company?_page=1&_limit=2
http://localhost:3000/company?_sort=id&_order=asc
http://localhost:3000/company?_sort=id&_order=desc
http://localhost:3000/user?age_gte=30
http://localhost:3000/user?age_gte=3&age_lte=31
http://localhost:3000/user?q=cu
post,patch,delete,需要下载postman,官方网站:[https://www.postman.com/downloads/](https://www.postman.com/downloads/),设置Headers,key是Content-Type,value是application/json,Body选择raw
{"name": "bryant", "phone": "333-444-555","email":"bryant@sina.com","age":41,"companyid":4}