Fork me on GitHub

API Creation

Creating and exposing APIs allows your web application to interact with other applications through machine-to-machine communication.

API creation frameworks

  • Django REST framework and Tastypie are the two most widely used API frameworks to use with Django. The edge currently goes to Django REST framework based on rough community sentiment. Django REST framework recently hit the 3.0 release mark after Tom Christie ran a successful Kickstarter campaign.

  • Flask-RESTful and Flask API are popular libraries for exposing APIs from Flask web applications.

  • Sandman is a widely used tool to automatically generate a RESTful API service from a legacy database without writing a line of code (though it's easily extensible through code).

  • Cornice is a REST framework for Pyramid.

  • Restless is a lightweight API framework that aims to be framework agnostic. The general concept is that you can use the same API code for Django, Flask, Bottle, Pyramid or any other WSGI framework with minimal porting effort.

  • Eve is a Python REST framework built with Flask, MongoDB and Redis. The framework's primary author Nicola Iarocci gave a great talk at EuroPython 2014 that introduced the main features of the framework.

API testing projects

Building, running and maintaining APIs requires as much effort as building, running and maintaining a web application. API testing frameworks are the equivalent of browser testing in the web application world.

  • zato-apitest invokes HTTP APIs and provides hooks for running through other testing frameworks.

Hosted API testing services

  • Runscope is an API testing SaaS application that can test both your own APIs and external APIs that your application relies upon.

  • API Science is focused on deep API testing, including multi-step API calls and monitoring of external APIs.

  • SmartBear has several API monitoring and testing tools for APIs.

API creation resources

API creation learning checklist

Pick an API framework appropriate for your web framework. For Django I recommend Django REST framework and for Flask I recommend Flask-RESTful.

Begin by building out a simple use case for the API. Generally the use case will either involve data that users want in a machine-readable format or a backend for alternative clients such as an iOS or Android mobile app.

Add an authentication mechanism through OAuth or a token scheme.

Add rate limiting to the API if data usage volume could be a performance issue. Also add basic metrics so you can determine how often the API is being accessed and whether it is performing properly.

Provide ample documentation and a walkthrough for how the API can be accessed and used.

Figure out other use cases and expand based on what you learned with the initial API use case.

What's next after building an API for your web app?

What are application programming interfaces?

How do I integrate external APIs into my application?

How can I learn about web application security?

Where should I host static content such as JavaScript files?


Interested in a complete Full Stack Python book with detailed tutorials and example code? Sign up here and you'll get an alert email if a book is created. No other emails will be sent other than sign up confirmation.