chapter four

4 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). We may also come across Message Queuing such as IBM Websphere MQ and RabbitMQ. Table 4.1 shows some pros and cons of the more common approaches to implementing APIs.

Table 4.1 Pros and Cons of different APIs
 
REST
SOAP
GraphQL
Pros
Simple, builds upon standard HTTP methods
Multiple data formats can be supported, although JSON is most common
Relies on XML based messaging
Enterprise-level security
Efficient
Single Endpoint
Strongly typed
Cons
Versioning and breaking changes can be complex to manage
Number of endpoints may become unwieldy
Complex to implement
Verbose XML based messages
Steeper learning curve

4.1 API Driven Design

4.2 Our APIs

4.3 Building Our APIs with FastAPI

4.3.1 Getting files with /files

4.3.2 Adding a file with POST

4.3.3 Finishing the rest of the APIs

4.4 Adding our API to Docker

4.4.1 Preparing the project

4.4.2 Docker Setup

4.5 Documenting our API

4.5.1 Swagger

4.5.2 Redoc

4.6 Managing our APIs

4.6.1 Benefits of API Management

4.10 Summary