Python REST APIs With Flask, Connexion, and SQLAlchemy

The goal of this article is to show you how to use Python 3, Flask, and Connexion to build useful REST APIs that can include input and output validation, and provide Swagger documentation as a bonus. Also included is a simple but useful single page web application that demonstrates using the API with JavaScript and updating the DOM with it.

The REST API you’ll be building will serve a simple people data structure where the people are keyed to the last name, and any updates are marked with a new timestamp.

This data could be represented in a database, saved in a file, or be accessible through some network protocol, but for us an in-memory data structure works fine. One of the purposes of an API is to decouple the data from the application that uses it, hiding the data implementation details.

API Creation: Full Stack Python

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

API creation frameworks

To Create An Evolvable API, Stop Thinking About URLs

The basics of API design

If you’re spending your time discussing if URLs should be in the singular /restaurant/:id or plural /restaurants/:id, then that means you’re not creating evolvable APIs.

.. The server may ask for all the fields in the first request, or they may acknowledge some fields and ask for the remaining ones in another request. The most important bit here is that the server responds to each interaction with the same interface.

.. This way you have no coupling between one specific URL and the response. One team can develop the client, and another team can develop the server; they only need to agree on the communication format. There’s no need to deploy both client and server at the same time in a specific order!

In Domain Driven Design, you model the architecture of the code with how the people from your business operate. With an evolvable API, it’s the same. You model the asynchronous communication between machines exactly how people in your business communicate.