Skip to content

Python one minute tutorial

atoji edited this page May 20, 2011 · 3 revisions

One minute guide

This is a one minute guide to get you going with Restfulie Python As soon as you finish this example you are up to the next guide and then move on to the features you want to explore more.

Configuring

Configuration should always be minimal and programmatic. To use Restfulie simply install its package:

python setup.py install

If you use 'pip', just run:

pip install restfulie

Or install with 'easy_install':

easy_install restfulie

Hypermedia

We are ready to go, hypermedia supported:

from restfulie import Restfulie

# using restfulie as an http api:
>>> response = Restfulie.accepts('application/xml').at('http://localhost:8080/items').get()
>>> print response.body
<items>
    <item>
        <name>Car</name>
        <price>32000.00</price>
    </item>
    <item>
        <name>House</name>
        <price>231000.00</price>
    </item>
</items>

>>> print response.code
200

# unmarshalling the items response
>>> r = response.resource()
>>> print len(r.item)
2
>>> print len(r.item[0].name)
Car

# navigating through hypermedia
>>> item = { 'name': 'New product', 'price': 30 }
>>> result = items.link("self").follow().post(item)

# or using parameters as kwargs
>>> result = items.link("self").follow().post(name='New Product', price=30)

>>> print result.code
200

This is it. Adding hypermedia capabilities and following links. Now its time to use it in the right way.

Clone this wiki locally