Skip to content

zmike808/wac

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

84 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wac

image

To write a friendly client for a RESTful API you typically end up doing the following:

  • Write HTTP client commands for communicating with the server. These commands do things like marshal payloads, convert errors, invoke request hooks, etc.
  • Turn responses deserialized by your client into resource objects (i.e. objectify the response).
  • Build up queries (e.g. filter, sort) to access resources matching some criteria in perhaps a particular order.

In the ideal case the client gives your users something approximating an ORM for your resources. This library is intended to assist you in writing such a client provided the API you are consuming complies with some basic conventions:

  • Uses HTTP properly.
  • Annotates resource representations with type and URI information.

Installation

Simply:

$ pip install wac

or if you prefer:

$ easy_install wac

Requirements

Usage

Lets work through an example. The code for this example is in example.py.

  • First you import wac:
  • Next define the version of your client:
  • Also define the configuration which all Clients will use by default:
  • Now be nice and define a function for updating the configuration(s):
  • Now the big one, define your Client which is what will be used to talk to a server:
  • Then define your base Resource:
  • And finally your actual resources:
  • Done! Now you can do crazy stuff like this:

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Write your code and tests
  4. Ensure all tests still pass (python setup.py test)
  5. Commit your changes (git commit -am 'Add some feature')
  6. Push to the branch (git push origin my-new-feature)
  7. Create new pull request

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%