Presented at djangocon 2011. Covers best practices for designing/ building RESTful APIs. Discusses the enhanced version of django-piston used by PBS Education.
----- Meeting Notes (9/7/11 09:17) -----Let's take a look at these company logos. You are familiar with most of them
Take a look again!
Because
So what’s the deal with promises & lies?
So how do start building APIs? Do you make a django project and spit some json out?
And you get magical API
Unfortunately, that’s not true
You just have to ask yourself a few questions..
RESTful APIs are stateless, cacheable and relies on HTTP methods
In RESTful APIs, handlers..
Speaking of resources
Resources are units of information that are of interest to your clients..
Units of information
Just like Kitkat
Now let’s take a look at the resource that can be built around that.. Besides some model attributes, it includes editions. Editions have further attributes that are of interest to API consumers. Lastly, there can be attributes that are very specific to the consumer requesting the resource.
Now let’s put them next to each other for a better understanding
Remember this guy
He always brought friends
Many friends
How was Neo able to fight them off, all by himself?
Because they were all agents Smiths. Their tactics were uniform. So Neo knew exactly how to approach them.
So wrap them in envelopes
Include information like.. when appropriate
For example you can deliver a response that has HTTP status code, errors and finally the data for a successful GET request
If a POST or PUT request fails, you can add the error metadata to your response.Makes it easy for the client to understand what exactly went wrong
Let’s take a look at a response that provides pagination information. You can include fields like how many results were found, how many pages that maps to etc.
You should remember..
It’s perfectly alright to have multiple serialization formats if you can accommodate the extra efforts
But don’t accept serialization formats as GET parameters
Like that
Or they can choose not to
Like that
Starting with Oauth 2.0 it’s mandated that you use HTTPS for calls to protected resources..
How do you minimize that complexity
Next, API frameworks
Next, API frameworks
A major feature we added was..
Lets take a look at that now.. this is how you’d define the resource for the Book model we previously discussed. It takes an object and uses your definitions to create a resource
Once you have that definition, you callit like this..
For example you can deliver a response that has HTTP status code, errors and finally the data for a successful GET request
You can find all necessary information about this enhanced django piston on PBS Education’s Github profile