“密码的API。”
mypasswords-api的Python项目详细描述
密码的API。
安装
这个python项目需要python 3.6,否则pip安装应该 工作正常:
$ pip install mypasswords-api
用法
默认情况下,我们可以将服务器运行为python模块,如下所示:
$ mypasswords_api 127.0.0.1:8000 ======== Running on http://127.0.0.1:8000 ========(Press CTRL+C to quit)
它将使用异步或uvloop启动一个aiohttp实例(如果 已安装),事件循环。
设置
要处理设置,我们使用简单设置组合行为。默认情况下 基本设置模块将尝试从当前环境中获取值:
$ MYPASSWORDS_PER_PAGE=100PG_HOST=localhost mypasswords_api 127.0.0.1:8000
API
创建
$ http POST http://127.0.0.1:8000/passwords login=toopy password=abcd1234 site=github.com HTTP/1.1 201 Created Content-Length: 110 Content-Type: application/json;charset=utf-8 Date: Sat, 09 Sep 201708:59:37 GMT Server: Python/3.6 aiohttp/2.2.0 X-API-Version: 0.1.0.dev0 {"id": "0753c165-0400-4e1f-b79c-8998d4987daf", "login": "toopy", "password": "abcd1234", "site": "github.com"}
更新
$ http PUT http://127.0.0.1:8000/passwords/0753c165-0400-4e1f-b79c-8998d4987daf login=toopy password=1234abcd site=github.com HTTP/1.1 200 OK Content-Length: 76 Content-Type: application/json;charset=utf-8 Date: Sat, 09 Sep 201709:05:47 GMT Server: Python/3.6 aiohttp/2.2.0 X-API-Version: 0.1.0.dev0 {"id": null, "login": "toopy", "password": "1234abcd", "site": "github.com"}
列表
$ http GET "http://127.0.0.1:8000/passwords?direction=desc&order_by=site&page1&per_page=2" HTTP/1.1 200 OK Content-Length: 212 Content-Type: application/json;charset=utf-8 Date: Sat, 09 Sep 201709:23:43 GMT Server: Python/3.6 aiohttp/2.2.0 X-API-Version: 0.1.0.dev0 X-Next-Link: /passwords?direction=desc&order_by=site&page=1&per_page=2[{"id": "f4a59e0f-f1ff-4bc7-8757-203fc4b0aff7", "login": "toopy", "password": null, "site": "twitter.com"}, {"id": "7ef3130f-7844-49c6-a46c-2f6960cae697", "login": "toopy", "password": null, "site": "slack.com"}]
搜索
$ http GET "http://127.0.0.1:8000/passwords?q=git" HTTP/1.1 200 OK Content-Length: 106 Content-Type: application/json;charset=utf-8 Date: Sat, 09 Sep 201709:46:26 GMT Server: Python/3.6 aiohttp/2.2.0 X-API-Version: 0.1.0.dev0 [{"id": "0753c165-0400-4e1f-b79c-8998d4987daf", "login": "toopy", "password": null, "site": "github.com"}]
获取
$ http GET http://127.0.0.1:8000/passwords/7ef3130f-7844-49c6-a46c-2f6960cae697 HTTP/1.1 200 OK Content-Length: 109 Content-Type: application/json;charset=utf-8 Date: Sat, 09 Sep 201709:24:33 GMT Server: Python/3.6 aiohttp/2.2.0 X-API-Version: 0.1.0.dev0 {"id": "7ef3130f-7844-49c6-a46c-2f6960cae697", "login": "toopy", "password": "1234abcd", "site": "slack.com"}
头部
$ http HEAD http://127.0.0.1:8000/passwords/7ef3130f-7844-49c6-a46c-2f6960cae697 HTTP/1.1 200 OK Content-Length: 0 Content-Type: application/json Date: Sat, 09 Sep 201709:24:46 GMT Server: Python/3.6 aiohttp/2.2.0 X-API-Version: 0.1.0.dev0
删除
$ http DELETE http://127.0.0.1:8000/passwords/7ef3130f-7844-49c6-a46c-2f6960cae697 HTTP/1.1 204 No Content Content-Length: 2 Content-Type: application/json;charset=utf-8 Date: Sat, 09 Sep 201709:46:55 GMT Server: Python/3.6 aiohttp/2.2.0 X-API-Version: 0.1.0.dev0
许可证
麻省理工学院许可证