evc-eve python rest api框架的简单客户端
evc的Python项目详细描述
EVC
evc-一个简单的“requests”http库包装器,它使用json格式进行传输,在基于“eve”框架向rest-api服务器执行http请求时自动解码到python字典并返回。
内容:Installation。| Requirements。| Running the tests。| Example of usage。| Versioning。| Authors。| License
开始
安装
来自PIP
pip install --upgrade evc
手动安装
git clone https://github.com/evbg/evc.git
cd evc
python setup.py install
直接从github.com上的repository安装
pip install git+https://github.com/evbg/evc.git
要求
pip install --upgrade evc
git clone https://github.com/evbg/evc.git
cd evc
python setup.py install
直接从github.com上的repository安装
pip install git+https://github.com/evbg/evc.git
要求
pip install git+https://github.com/evbg/evc.git
evc需要requests和simplejson库。
运行测试
evc已经在以下python版本上进行了测试:2.7、3.4、3.5、3.6、3.7、pypy、pypy3。
EVE框架集成测试
先决条件
要在本地主机上运行测试,必须在禁用访问控制的情况下启动MongoDB服务。
通过tox工具运行测试
git clone https://github.com/evbg/evc.git
cd evc
tox
用法示例
git clone https://github.com/evbg/evc.git
cd evc
tox
下面的示例演示如何通过python交互式shell使用evc:
首先,运行服务器“eve”
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from eve import Eve
>>> settings = {'XML': False, 'JSON': True, 'SERVER_NAME': '127.0.0.1:5555', 'MONGO_DBNAME': 'evc_test'}
>>> settings['RESOURCE_METHODS'] = ['GET', 'POST', 'DELETE']
>>> settings['ITEM_METHODS'] = ['GET', 'PATCH', 'PUT', 'DELETE']
>>> settings['DOMAIN'] = {'persons': {'versioning': True, 'allow_unknown': True, 'schema': {}}}
>>> app = Eve(settings=settings)
>>> app.run()
* Running on http://127.0.0.1:5555/ (Press CTRL+C to quit)
其次,运行客户端“evc”
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
Type "copyright", "credits" or "license" for more information.
IPython 5.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: from evc import Evc
In [2]: REST = Evc('http://127.0.0.1:5555')
In [3]: type(REST.response)
Out[3]: NoneType
In [4]: REST.get()
Out[4]: {u'_links': {u'child': [{u'href': u'persons', u'title': u'persons'}]}}
In [5]: type(REST.response)
Out[5]: requests.models.Response
In [6]: REST.response.text
Out[6]: u'{"_links": {"child": [{"href": "persons", "title": "persons"}]}}'
In [7]: REST.response.json
Out[7]: <bound method Response.json of <Response [200]>>
In [8]: REST.response.json()
Out[8]: {u'_links': {u'child': [{u'href': u'persons', u'title': u'persons'}]}}
In [9]: REST.post('persons', {'name': 'Bob', 'email': 'bob@bobmail.com'})
Out[9]:
{u'_created': u'Tue, 25 Oct 2016 10:46:39 GMT',
u'_etag': u'90d02265b8d7c832247fcaeacf11d1f4bbf8f0bc',
u'_id': u'580f380fa7a3497495d72bd4',
u'_latest_version': 1,
u'_links': {u'self': {u'href': u'persons/580f380fa7a3497495d72bd4',
u'title': u'Person'}},
u'_status': u'OK',
u'_updated': u'Tue, 25 Oct 2016 10:46:39 GMT',
u'_version': 1}
In [10]: REST.patch('persons', '580f380fa7a3497495d72bd4', '90d02265b8d7c832247fcaeacf11d1f4bbf8f0bc', {'name': 'Bob', 'email': 'bob2@bobmail.com'})
Out[10]:
{u'_created': u'Tue, 25 Oct 2016 10:46:39 GMT',
u'_etag': u'50da6d8e759eeb0a32eaf0bd820dcfb729cdf5d9',
u'_id': u'580f380fa7a3497495d72bd4',
u'_latest_version': 2,
u'_links': {u'self': {u'href': u'persons/580f380fa7a3497495d72bd4',
u'title': u'Person'}},
u'_status': u'OK',
u'_updated': u'Tue, 25 Oct 2016 10:48:20 GMT',
u'_version': 2}
In [11]: REST.delete('persons', '580f380fa7a3497495d72bd4', '50da6d8e759eeb0a32eaf0bd820dcfb729cdf5d9')
Out[11]: u''
In [12]: REST.get('persons', '580f380fa7a3497495d72bd4')
Out[12]:
{u'_items': [],
u'_links': {u'parent': {u'href': u'/', u'title': u'home'},
u'self': {u'href': u'persons', u'title': u'persons'}},
u'_meta': {u'max_results': 25, u'page': 1, u'total': 0}}
版本控制
我们使用SemVer进行版本控制。
作者
- evgeny v.bogodukhov-初始工作-evbg
许可证
这个项目是在麻省理工学院的许可下授权的-请参见LICENSE文件以了解详细信息