SlideShare a Scribd company logo
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 ?
●   Let's REST with Django...
REST
Practical REST

●   Building a web for computers
    ●   They (computers) want to find 'computer-friendly'
        pages
    ●   They love well organised data/information
    ●   They don't mind about ”visual appeal”
●   Side note: There is no ”Google” for them [yet].
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:
    ●   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, ...
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
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
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 Idempotence
HTTP
●   HTTP is your best friend
●   Requests
●   Headers
●   Body
●   Status (return) codes
    ●   2xx – Success
    ●   3xx – ???
    ●   4xx – ???
    ●   5xx – Server Error
Django + REST
General Approach

                                   urls.py
 urls.py                                                 JSON
                   HTML



                                             views.py
            views.py



                                             models.py
models.py

                       templates
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 item's URI returns a representation of that item
        (resource)
    ●   ”Safe”
Methods (contd.)
●   POST
    ●   Points to a collection URI
    ●   Creates a new resource in that collection
    ●   We don't 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
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.
Recommended Tools
●   Firefox 3.x
    ●   FireBug (Net tab) or HTTPFox
    ●   Poster
    ●   SQLite Manager
    ●   JSONView
    ●   Modify Headers
●   Wireshark
Recommended Books
RESTful Web Services, Leonard     Pro Django, Marty Alchin, Apress
Richardson & Sam Ruby, O'Reilly

More Related Content

PDF
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
PDF
Microformats I: What & Why
PPTX
IPTC News in JSON Spring 2013
PDF
Search Concepts & Tools
PPTX
2016.02 - Validating RDF Data Quality using Constraints to Direct the Develop...
PDF
JustJava 2005: Web Services em Java com o JWSDP 1.5
PDF
Publishing Linked Data using Schema.org
PPTX
Ontology Access Kit_ Workshop Intro Slides.pptx
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
Microformats I: What & Why
IPTC News in JSON Spring 2013
Search Concepts & Tools
2016.02 - Validating RDF Data Quality using Constraints to Direct the Develop...
JustJava 2005: Web Services em Java com o JWSDP 1.5
Publishing Linked Data using Schema.org
Ontology Access Kit_ Workshop Intro Slides.pptx

Similar to Python Ireland Nov 2010 - RESTing with Django (20)

ODP
REST API Laravel
PDF
The Semantic Web and Drupal 7 - Loja 2013
PDF
A content repository for your PHP application or CMS?
PDF
Drupal and the Semantic Web - ESIP Webinar
PDF
Getting started with DSpace 7 REST API
PDF
Development without Constraint
PDF
GraphQL is actually rest
PDF
The Future of Search and SEO in Drupal
PPTX
Hacktoberfest 2020 - Intro to Knowledge Graphs
PDF
NoSQL
PDF
MongoDB Basics
PDF
Devoxx 2008 - REST in Peace
PPTX
A Deep Dive into RESTful API Design Part 2
PDF
Slides semantic web and Drupal 7 NYCCamp 2012
PPTX
Pragmatic REST APIs
PDF
Drupal and the semantic web - SemTechBiz 2012
PDF
Java Web Services [5/5]: REST and JAX-RS
PDF
Intro to Hypermedia APIs
PPTX
Restful webservice
PDF
Real time semantic search engine for social tv streams
REST API Laravel
The Semantic Web and Drupal 7 - Loja 2013
A content repository for your PHP application or CMS?
Drupal and the Semantic Web - ESIP Webinar
Getting started with DSpace 7 REST API
Development without Constraint
GraphQL is actually rest
The Future of Search and SEO in Drupal
Hacktoberfest 2020 - Intro to Knowledge Graphs
NoSQL
MongoDB Basics
Devoxx 2008 - REST in Peace
A Deep Dive into RESTful API Design Part 2
Slides semantic web and Drupal 7 NYCCamp 2012
Pragmatic REST APIs
Drupal and the semantic web - SemTechBiz 2012
Java Web Services [5/5]: REST and JAX-RS
Intro to Hypermedia APIs
Restful webservice
Real time semantic search engine for social tv streams
Ad

More from Python Ireland (20)

PDF
Async I/O in Python
PDF
Python Ireland 2012 - Message brokers and Python by Fernando Ciciliati
PDF
Python Ireland - Who, how, what
PPT
Object Orientation vs. Functional Programming in Python
PDF
What's the Scoop with Python 3?
PDF
Google App Engine in 40 minutes (the absolute essentials)
PDF
Introduction to Erlang for Python Programmers
PPT
Web-service based Mobile Geospatial Application Development using Python
PDF
Utopia Kingdoms scaling case. From 4 users to 50.000+
PPT
The Larch - a visual interactive programming environment
PDF
Python vs JLizard.... a python logging experience
PDF
Vim and Python
PDF
Python Ireland Nov 2009 Talk - Appengine
ODP
Python Ireland May 2011 - What is Pyramid and where is it with respect to Dja...
PDF
Python Ireland Nov 2010 Talk: Unit Testing
ODP
Python Ireland Feb '11 Talks: Introduction to Python
PPTX
Python Ireland Dec Talks - Windows Azure -- The Nuts and Bolts
PDF
KEY
Python for cloud computing
ODP
IPython: The awesome python shell
Async I/O in Python
Python Ireland 2012 - Message brokers and Python by Fernando Ciciliati
Python Ireland - Who, how, what
Object Orientation vs. Functional Programming in Python
What's the Scoop with Python 3?
Google App Engine in 40 minutes (the absolute essentials)
Introduction to Erlang for Python Programmers
Web-service based Mobile Geospatial Application Development using Python
Utopia Kingdoms scaling case. From 4 users to 50.000+
The Larch - a visual interactive programming environment
Python vs JLizard.... a python logging experience
Vim and Python
Python Ireland Nov 2009 Talk - Appengine
Python Ireland May 2011 - What is Pyramid and where is it with respect to Dja...
Python Ireland Nov 2010 Talk: Unit Testing
Python Ireland Feb '11 Talks: Introduction to Python
Python Ireland Dec Talks - Windows Azure -- The Nuts and Bolts
Python for cloud computing
IPython: The awesome python shell
Ad

Recently uploaded (20)

PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
cuic standard and advanced reporting.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
KodekX | Application Modernization Development
PPTX
Cloud computing and distributed systems.
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPT
Teaching material agriculture food technology
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Encapsulation theory and applications.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
sap open course for s4hana steps from ECC to s4
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
cuic standard and advanced reporting.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
KodekX | Application Modernization Development
Cloud computing and distributed systems.
The AUB Centre for AI in Media Proposal.docx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Teaching material agriculture food technology
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Encapsulation theory and applications.pdf
Spectral efficient network and resource selection model in 5G networks
Understanding_Digital_Forensics_Presentation.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Programs and apps: productivity, graphics, security and other tools
Unlocking AI with Model Context Protocol (MCP)
Per capita expenditure prediction using model stacking based on satellite ima...
sap open course for s4hana steps from ECC to s4

Python Ireland Nov 2010 - RESTing with Django

  • 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 ? ● Let's REST with Django...
  • 4. Practical REST ● Building a web for computers ● They (computers) want to find 'computer-friendly' pages ● They love well organised data/information ● They don't 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
  • 13. General Approach urls.py urls.py JSON HTML views.py views.py models.py models.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 item's 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 don't 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 Books RESTful Web Services, Leonard Pro Django, Marty Alchin, Apress Richardson & Sam Ruby, O'Reilly