An API to your project lets people write applications that use your technology. Web APIs are collections of URLs pointing to services. Tuesday, June 25, 13
get back like: yoursite.com/show/articles?article_id=42 Used to be super common, until REST pattern emerged good luck with that Often inconsistent & needs a lot of docs Response data isn’t linked to DB records Tuesday, June 25, 13
POST /article/ gets back JSON with a saved article ID GET /article/ gets back a list of article IDs { ‘article’: { ‘id’: 42, ‘author’: ‘Becky Smith’, ‘title’: ‘API Design 101’ }} Tuesday, June 25, 13
REST pattern. There are free API libraries for Python web frameworks. This all works well for creating APIs to relational data. BUT WAIT What if your data is too complex to store in a DB table? Tuesday, June 25, 13
search tools. Upload a photo? POST to /upload/ with file + metadata Get photo details? GET /photo/ Want to let your API users calculate the average color in some random images? ... Hmm. Tuesday, June 25, 13
uploaded_at = models.DateTimeField() file = models.FileField(blank=True, null=True) How do you turn this model into an API? Try Tastypie. Tuesday, June 25, 13
= Api(api_name='api') urlpatterns = patterns(‘’, include(photo_api.urls)) # ... other routes in your app can go # into this urlpatterns definition, if you want Tuesday, June 25, 13
data? Can we see data about all photos we’ve uploaded? Yup. Sure. Check it out. GET /api/photo/42 GET /api/photo/ POST /api/photo/ Where are we now? Tuesday, June 25, 13
2. In views.py, create any helper methods you need for your Photo model. 3. In api.py, use prepend_urls to add an RPC URL pattern for the new PhotoResource method. Mix in an RPC URL. Tuesday, June 25, 13