RESTing with DJANGO   Fernando Ciciliati   Python Ireland November Meet-up   10/11/2010 – The Science Gallery – Dublin
Contents●   Quick review of REST ?●   Even quicker review of Django ?●   Lets REST with Django...
REST
Practical REST●   Building a web for computers    ●   They (computers) want to find computer-friendly        pages    ●   ...
REST Keywords●   Resource●   ”Resource name” or URI [or URL]●   Representation●   Methods/Verbs (Uniform Interface)●   Links
REST: Resource●   Any entity, object or concept we want our    application to keep information about●   Obvious resources:...
REST: Resource Name●   Every resource should receive at least one    name that identifies it uniquely in its context of   ...
REST: Representation●   Representations are the materialization, in    bytes and bits, of resources.●   Resources are idea...
REST: Uniform Interface●   Minimize number of ”verbs”    ●   REST x ”WebServices”●   Stick to HTTP verbs
Core REST principles●   Addressability●   State and statelessness●   Conectedness●   Uniform Interface    ●   Safety and I...
HTTP●   HTTP is your best friend●   Requests●   Headers●   Body●   Status (return) codes    ●   2xx – Success    ●   3xx –...
Django + REST
General Approach                                   urls.py urls.py                                                 JSON   ...
Methods●   OPTIONS    ●   Should be always available with any URI    ●   Returns a list of available methods for that URI ...
Methods (contd.)●   POST    ●   Points to a collection URI    ●   Creates a new resource in that collection    ●   We dont...
Methods (contd.)●   DELETE    ●   Usually points to a resouce URI    ●   Deletes the resource    ●   Retry strategy is not...
Recommended Tools●   Firefox 3.x    ●   FireBug (Net tab) or HTTPFox    ●   Poster    ●   SQLite Manager    ●   JSONView  ...
Recommended BooksRESTful Web Services, Leonard     Pro Django, Marty Alchin, ApressRichardson & Sam Ruby, OReilly
Upcoming SlideShare
Loading in …5
×

Python Ireland Nov 2010 - RESTing with Django

748 views

Published on

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.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
748
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Python Ireland Nov 2010 - RESTing with Django

  1. 1. RESTing with DJANGO Fernando Ciciliati Python Ireland November Meet-up 10/11/2010 – The Science Gallery – Dublin
  2. 2. Contents● Quick review of REST ?● Even quicker review of Django ?● Lets REST with Django...
  3. 3. REST
  4. 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. 5. REST Keywords● Resource● ”Resource name” or URI [or URL]● Representation● Methods/Verbs (Uniform Interface)● Links
  6. 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. 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. 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. 9. REST: Uniform Interface● Minimize number of ”verbs” ● REST x ”WebServices”● Stick to HTTP verbs
  10. 10. Core REST principles● Addressability● State and statelessness● Conectedness● Uniform Interface ● Safety and Idempotence
  11. 11. HTTP● HTTP is your best friend● Requests● Headers● Body● Status (return) codes ● 2xx – Success ● 3xx – ??? ● 4xx – ??? ● 5xx – Server Error
  12. 12. Django + REST
  13. 13. General Approach urls.py urls.py JSON HTML views.py views.py models.pymodels.py templates
  14. 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. 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. 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. 17. Recommended Tools● Firefox 3.x ● FireBug (Net tab) or HTTPFox ● Poster ● SQLite Manager ● JSONView ● Modify Headers● Wireshark
  18. 18. Recommended BooksRESTful Web Services, Leonard Pro Django, Marty Alchin, ApressRichardson & Sam Ruby, OReilly

×