Birmingham-mumbai


Managing user requests and server response



tải về 6.62 Mb.
Chế độ xem pdf
trang16/275
Chuyển đổi dữ liệu09.10.2023
Kích6.62 Mb.
#55278
1   ...   12   13   14   15   16   17   18   19   ...   275
Sherwin John Tragura - Building Python Microservices with FastAPI Build secure, scalable, and structured Python microservices from design concepts to infrastructure-Packt Publishing - ebooks Account

Managing user requests and server response
Clients can pass their request data to FastAPI endpoint URLs through path parameters, query parameters
or headers to pursue service transactions. There are standards and ways to use these parameters to 
obtain incoming requests. Depending on the goal of the services, we use these parameters to influence 
and build the necessary responses the clients need. But before we discuss these various parameter 
types, let us explore first how we use type hinting in FastAPI’s local parameter declaration.
Parameter type declaration
All request parameters are required to be type-declared in the method signature of the service method 
applying the 
PEP 484
standard called type hints. FastAPI supports common types such as 
None

bool

int
, and 
float
and container types such as 
list

tuple

dict

set

frozenset
, and 
deque
. Other complex Python types such as 
datetime.date

datetime.time

datetime.
datetime

datetime.delta

UUID

bytes
, and 
Decimal
are also supported. 
The framework also supports the data types included in Python’s 
typing
module, responsible for 
type hints. These data types are standard notations for Python and variable type annotations that can 
help to pursue type checking and model validation during compilation, such as 
Optional

List

Dict

Set

Union

Tuple

FrozenSet

Iterable
, and 
Deque
.
Path parameters
FastAPI allows you to obtain request data from the endpoint URL of an API through a path parameter 
or path variable that makes the URL somewhat dynamic. This parameter holds a value that becomes 
tải về 6.62 Mb.

Chia sẻ với bạn bè của bạn:
1   ...   12   13   14   15   16   17   18   19   ...   275




Cơ sở dữ liệu được bảo vệ bởi bản quyền ©hocday.com 2024
được sử dụng cho việc quản lý

    Quê hương