Skip to content

Chapter 2

Chapter 2

  • http verb: GET
  • Path operation decorator
  • sometimes, one or more parameters may be appended to the URL as a query string and meant to be processed by the script: http://example.com/hello.php?name=FirstName&marks=75
  • The modern web uses a route-based approach, which makes the URL as http://example.com/FirstName/75. The URL has three distinct parts: the protocol (http:// or https://) followed by the IP address or hostname. The remaining part of the URL after the first / after the hostname is called the path or endpoint.
  • API Docs
  • FastAPI's design follows the OpenAPI specification (OAS) for API creation and declaration of path opeartions, parameters, etc. It also autogenerates the documentatin of data models with JSON Schema. JSON schema defines a JSON-based media type called "application/schema+json". It is a format for describing the structure of JSON data.
    • By default, FastAPI uses Swagger UI and Redoc
  • Path Parameters
  • This path can be a mixture of fixed part and a variable part.
  • Generally, the fixed part referes to a collection of resources available to the server, and the variable part (which may have one or more values) is used to locate or retrieve a specific resource from the collection.
  • As already stated, the FastAPI application object acts as a router, directing the incoming request from the client to the appropriate handler function. It checks the request URL matches with the pattern declared in which opeartion decorator.
  • Query Parameters
  • If a certain operation function (also called a view function) below the path decorator has some parameters in addition to the placeholders in the URL pattern, FastAPI deems them to be query parameters.
  • Path and Query has a lot of configurations. See chap2/app_fastapi.py for more examples.