FastAPI - OpenAPI



Enter the following URL in the browser to generate automatically the interactive documentation.

http://127.0.0.1:8000/docs

FastAPI uses Swagger UI to produce this documentation. The browser will display the following −

FastAPI OpenAPI

Click the 'try it out' button and then 'Execute' button that appears afterward.

FastAPI OpenAPI1

You can see the Curl command internally executed, the request URL, the response headers, and the JSON format of the server’s response.

FastAPI generates a schema using OpenAPI specifications. The specification determines how to define API paths, path parameters, etc. The API schema defined by the OpenAPI standard decides how the data is sent using JSON Schema. Visit http://127.0.0.1:8000/openapi.json from your browser. A neatly formatted JSON response as follows will be displayed −

{
   "openapi": "3.0.2",
   "info": {
      "title": "FastAPI",
      "version": "0.1.0"
   },
   "paths": {
      "/": {
         "get": {
            "summary": "Index",
            "operationId": "index__get",
            "responses": {
               "200": {
                  "description": "Successful Response",
                  "content": {
                     "application/json": {
                        "schema": {}
                     }
                  }
               }
            }
         }
      }
   }
}

FastAPI also supports another automatic documentation method provided by Redoc ( https://github.com/Redocly/redoc).

Enter http://localhost:8000/redoc as URL in the browser’s address bar.

FastAPI Github
Advertisements