Full Stack Python

# 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

- Choosing an API framework for Django by PyDanny contains questions and insight into what makes a good API framework and which one you should currently choose for Django.

- RESTful web services with Python is an interesting overview of the Python API frameworks space.

- 10 Reasons Why Developers Hate Your API (And what to do about it) goes through the top difficulties and annoyances developers face when working with APIs and how you can avoid your API falling into the same traps.

- Versioning of RESTful APIs is a difficult and contentious topic in the web API community. This two-part series covers various ways to version your API and how to architect a version-less API.

- NARWHL is a practical API design site for developers confused about what is appropriate for RESTful APIs.

- Implementing a RESTful Web API with Python & Flask is a straightforward introduction to using Flask to create request handling and responses to produce a web API.

- This API Design Guide is based on Heroku's best practices for the platform's API.

- 18F's API standards explains the details behind their design decisions on creating modern RESTful APIs.

- Design a beautiful REST API reviews common design decisions regarding endpoints, versioning, errors and pagination. There is also a source material YouTube video where this blog post derives its recommendations from.

- Move Fast, Don't Break Your API are slides and a detailed blog post from Amber Feng at Stripe about building an API, separating layers of responsibility, hiding backwards compatibility and a whole slew of other great advice for developers and API designers.

- Self-descriptive, isn't. Don't assume anything. is an appeal that metadata makes a difference in whether APIs are descriptive or not.

- Designing the Artsy API has their recommendations list for building an API based on their recent experiences.

- Some REST Best Practices is a high level summary of rules to follow while creating your API.

## 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 major updates to this site or an alert when a complete Full Stack Python book with detailed example code is released? Sign up here and you'll an occasional email only when there's big news to report.