Reputation: 15143
I have a REST API, say:
http://localhost/api/v1/foo1
http://localhost/api/v1/foo2
http://localhost/api/v1/foo3
I'd like to have a python client that would look something like
api({some kinda init code})
result1 = api.get_foo1(params)
result2 = api.post_foo2(params)
result2 = api.post_foo2(params)
I'm really lazy and I was wondering if there's some existing python package that would generate such an API for me.
I've already done some searching in SO, the best approach I've found so far is to use the python-requests package, and write my own wrapper to pretty it up. Is there anything easier?
Upvotes: 4
Views: 1802
Reputation: 8795
You can try using the python-rest-client on Google Code, where you would make calls that look like this:
conn.request_get("/search", args={'q':'Test'}, headers={'Accept':'text/json'})
But as you can quickly see you will still need to create a wrapper of some sort to achieve the simplicity of your example calls.
Remember that with REST, you don't have foreknowledge of what the service call will return, so you can't have a one-size-fits-all API for REST. Ultimately, you'll need to wrap your http calls into something that's convenient for your needs.
I recommend doing this yourself - this will help you with your maintenance as you aren't introducing a layer of abstraction in between your client and the API itself.
Upvotes: 2