cli访问restful服务
crest的Python项目详细描述
一个通用的cli,可以通过少量配置访问任何restful服务。 把它想象成介于curl和适当cli之间的东西。
特点:
- 使用简单的object.property[index]符号发送请求时替换json请求正文的部分
- 使用上述符号仅打印部分json响应
- 历史记录:以前发送的请求被存储,可以使用--last选项重新发送
- 模板:存储特定url的预设请求,并使用--template选项发送它们
- 服务配置:在配置中存储特定服务的公用头、url前缀、预设请求
它有类似curl的选项来获取和提供请求体。-d,-H和-d是 和卷发一样。-X已更改为-m。目前,该工具使用requests发送 http请求。将来,它可能只是curl之上的包装器,将所有选项委托给 卷曲。
示例用法:
以下configuration在~/.crest/raxid/config.py中:
tokens_request = { "auth": { "passwordCredentials":{ "username":"REPLACE_USERNAME", "password":"REPLACE_PASSWORD" } } } config = { "name": "raxid", "description": "Rackspace Identity Service", "uriprefix": "https://identity.api.rackspacecloud.com/v2.0", "headers": { "accept": "application/json", "content-type": "application/json" }, "resources": { "tokens/?$": { "templates": {"default": tokens_request}, "aliases": { "username": "auth.passwordCredentials.username", "password": "auth.passwordCredentials.password", }, "help": "Authenticate via username/password" } } }
可以通过Rackspace Identity Service身份验证 并使用以下命令提取令牌:
crest -s raxid tokens -m post -t -r username=myuname -r password=mypwd -o access.token.id
有关详细信息,请查看usage
安装
pip install crest mkdir -p ~/.crest/generic_history # for --history and --service to work
谢谢
感谢Rackspace在侧边项目上有黑客文化,并允许我在这方面进行工作,以及 优秀的open source employee contribution policy