json作为rest api
jason-server的Python项目详细描述
Jason服务器
获取完整的假rest api
目录
开始
安装Jason服务器
pip3installjason-server
用一些数据创建一个db.json
文件
{"articles":[{"id":1,"title":"jason-server","author":"1"},{"id":2,"title":"jason-routes","author":"1"}],"authors":[{"id":1,"name":"bob"}]}
启动json服务器
jason-server watch db.json
现在,如果您转到http://localhost:8080/articles,您将获得
{"id":1,"title":"jason-server","author":"1"},{"id":2,"title":"jason-routes","author":"1"}
路线
单一路线
GET /authors
多条路线
GET /authors
GET /authors/1
过滤器
GET /articles?title=title&author=eminem
分页
使用_page
和_limit
对数据分页。
在Link
头中,您将获得first
、prev
、next
和last
链接。
GET /articles?_page=2
GET /articles?_page=3&_limit=15
排序
使用_sort
和_order
(默认顺序:asccentant)
GET /persons?_sort=age
GET /persons?_sort=name&_order=desc
数据库
GET /db
额外费用
替代宿主
您可以使用--host
标志在其他主机上启动json服务器:
$ json-server --host "0.0.0.0" watch db.json
默认值:localhost
替代端口
您可以使用--port
标志在其他端口上启动json服务器:
$ json-server --port 8100 watch db.json
默认值:8080
cli用法
Usage: jason-server [OPTIONS] COMMAND [ARGS]... Options: -h, --host TEXT Host adress -p, --port INTEGER Port -q, --quiet --version Show the version and exit. --help Show this message and exit. Commands: watch Run your database as REST Api
学分
许可证
代码在MIT许可下可用。