Test and Create an HTTP Endpoint
Learn to create and test HTTP endpoints.
Before we create the proper setup of the web server, we need to create the endpoint that will be exposed. Endpoints are ultimately run when a user sends a request to a certain URL. This means that we can still work with
Our objective right now is to test an endpoint while ensuring that our web server remains up and running when we hit the test URLs. The web server itself is an external system, so we won’t test it, but the code that provides the endpoint is part of our application. It’s a gateway interface that allows an HTTP framework to access the use cases.
The extension pytest-flask
allows us to run Flask, simulate HTTP requests, and test the HTTP responses. This extension hides a lot of automation. When we install it, some fixtures like client
become available automatically, so we don’t need to import them. Moreover, it tries to access another fixture named app
. Our first step should be to define this fixture when we begin to create our endpoint. ...