Python Ireland Nov 2010 - RESTing with Django

  • 490 views
Uploaded on

RESTing with Django - Fernando Ciciliati …

RESTing with Django - Fernando Ciciliati

Abstract: Django at the heart of enterprise systems: Building RESTful web services and integration components with Django.

Level: Medium, but beginner-friendly: A very quick introduction to Django and/or to REST will be offered if required by the attendees.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
490
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
8
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. RESTing with DJANGO Fernando Ciciliati Python Ireland November Meet-up 10/11/2010 – The Science Gallery – Dublin
  • 2. Contents● Quick review of REST ?● Even quicker review of Django ?● Lets REST with Django...
  • 3. REST
  • 4. Practical REST● Building a web for computers ● They (computers) want to find computer-friendly pages ● They love well organised data/information ● They dont mind about ”visual appeal”● Side note: There is no ”Google” for them [yet].
  • 5. REST Keywords● Resource● ”Resource name” or URI [or URL]● Representation● Methods/Verbs (Uniform Interface)● Links
  • 6. REST: Resource● Any entity, object or concept we want our application to keep information about● Obvious resources: ● Books, people, employees, cities, blog entries, bank accounts, hotels, flights, ..● Slightly less obvious: ● Money transfers, hotel reservations, flight tickets, …● Even less obvious: ● User session, transaction, ...
  • 7. REST: Resource Name● Every resource should receive at least one name that identifies it uniquely in its context of usage or existence – ideally, in the world.● This name should be durable, persistent.● Typical naming schemas: URLs, URIs, URNs● It is OK to have more than one name identifying the same resource
  • 8. REST: Representation● Representations are the materialization, in bytes and bits, of resources.● Resources are ideas, concepts; representations are ”physical”, ”tangible” REPRESENTATIONS of ideas● Multiple formats possible● A single resource can have multiple representations associated to it
  • 9. REST: Uniform Interface● Minimize number of ”verbs” ● REST x ”WebServices”● Stick to HTTP verbs
  • 10. Core REST principles● Addressability● State and statelessness● Conectedness● Uniform Interface ● Safety and Idempotence
  • 11. HTTP● HTTP is your best friend● Requests● Headers● Body● Status (return) codes ● 2xx – Success ● 3xx – ??? ● 4xx – ??? ● 5xx – Server Error
  • 12. Django + REST
  • 13. General Approach urls.py urls.py JSON HTML views.py views.py models.pymodels.py templates
  • 14. Methods● OPTIONS ● Should be always available with any URI ● Returns a list of available methods for that URI in the ”Allow” header of the HTTP response;● GET ● on a collection URI returns a list of items in that collection – for large collections, consider paging ● on an items URI returns a representation of that item (resource) ● ”Safe”
  • 15. Methods (contd.)● POST ● Points to a collection URI ● Creates a new resource in that collection ● We dont know the resource-id beforehand ● Not idempotent!● PUT ● Points to an item URI ● We KNOW the resource-id ● Creates a new resource or updated an existing one ● Idempotent
  • 16. Methods (contd.)● DELETE ● Usually points to a resouce URI ● Deletes the resource ● Retry strategy is not a problem● HEAD ● Like GET, but returns only headers, no body ● Good for retrieving information about the resource as its size, language, content type, etc., without transmitting the entire resource.
  • 17. Recommended Tools● Firefox 3.x ● FireBug (Net tab) or HTTPFox ● Poster ● SQLite Manager ● JSONView ● Modify Headers● Wireshark
  • 18. Recommended BooksRESTful Web Services, Leonard Pro Django, Marty Alchin, ApressRichardson & Sam Ruby, OReilly