Swagger and HTTPie Testing Clients
00:00 As mentioned, REST APIs aren’t meant to be accessed by a web browser. They’re designed to be consumed by other applications. Therefore, it helps to have a client to interact with them during development, and web browsers just aren’t up to the task. You could use a tool such as Postman, and if you are already using Postman, there is no reason you can’t continue to use it with FastAPI.
00:40 This is a browser-based tool for interacting with and testing REST APIs. FastAPI uses it to provide interactive documentation. Notice that the endpoint you created for the Root of the application is listed, and it uses the GET method. Later in the course, you’ll see how to use the POST method. Expand the item to see an abundance of information about how to access the endpoint, what data it expects, and what data it returns, and any errors that could occur.
01:21 If the endpoint expected any inputs, Swagger would prompt you to provide them, as you’ll see later. But this simple endpoint doesn’t accept any, so click the Execute button to invoke the endpoint.
Scroll down and you can see the JSON that was returned for the
Hello world message by FastAPI. In addition, it returned a
200 OK HTTP status code, and you can see the headers of the response as well. Later in the course, you’ll see how Swagger handles errors for parameters and incorrect types.
You can see the JSON that was returned for the
Hello world message. And again, the API also returned to
200 status code, which is OK, and some headers, since the API currently only responds to GET requests.
So the API returns a
405 status code, which means that the method
POST is not allowed. Later in the course, you’ll see that, in addition to the
@get decorator, there are
Become a Member to join the conversation.