chapter five

5 APIs – The piping between our components

 

This chapter covers

  • Introduction to the FastAPI Framework
  • Documenting our APIs using the OpenAPI Standard
  • Testing our APIs using Postman and Locust
  • API Management with WSO2

An Application Program Interface (API) is simply a way to interact with a software component. Generally, when we speak about APIs we are talking about the REST (Representational State Transfer) API standard. However, there are other standards such as GraphQL and the older SOAP (Simple Object Access Protocol).

The APIs act as a contract which both parties agree to abide by. For the consumer of the API, we agree to abide by any terms of use and licensing agreements and to follow any documentation and standards that have been established by the provider. In turn, the provider of an API provides a stable and scalable endpoint for us to access. Subscriptions to APIs will also provide tools to make costs/usage transparent as well as a Service Level Agreement (SLA).

5.1 API Driven Design

With the adoption of distributed computing, many developers and architects have taken an interest in an API Driven Design approach. Often, we can expect our software to be deployed to the cloud or into a containerized environment. In these instances, we want to make sure we have given thought to the API. As with most design objectives we want to keep some of the following things in mind.

5.2 Our APIs

5.3 Building Our APIs with FastAPI

5.3.1 Getting files with /files

5.3.2 Adding a file with POST

5.3.3 Finishing the rest of the APIs

5.4 Adding our API to Docker

5.4.1 Preparing the project

5.4.2 Docker Setup

5.5 Documenting our API

5.5.1 Swagger

5.5.2 Redoc

5.6 Managing our APIs

5.6.1 Benefits of API Management

5.6.2 Adding WSO2 API Manager to our Project

5.6.3 OpenAPI Version

5.6.4 Create an API in WSO2

5.6.5 Troubleshooting

5.7 Testing with Postman

5.8 Load Testing with Locust

5.9 Improving our code

5.9.1 Using a prefix and versioning

5.9.2 Adding Pydantic

5.9.3 Validation with Pydantic

5.9.4 Troubleshooting Pydantic

5.10 Summary