apifrom.core.requestο
Request module for APIFromAnything.
This module defines the Request class that represents an HTTP request and provides methods for accessing request data.
Overviewο
Classes
Classesο
- class apifrom.core.request.Request(request=None, path_params=None, method=None, path=None, query_params=None, headers=None, body=None, client_ip=None)[source]ο
Request class for APIFromAnything.
This class wraps a Starlette request and provides methods for accessing request data in a convenient way.
- apifrom.core.request._requestο
The underlying Starlette request.
- apifrom.core.request.path_paramsο
Path parameters extracted from the URL.
- apifrom.core.request.query_paramsο
Query parameters extracted from the URL.
- apifrom.core.request.headersο
HTTP headers.
- apifrom.core.request.methodο
HTTP method.
- apifrom.core.request.pathο
Request path.
- apifrom.core.request._bodyο
Cached request body.
Initialize a new Request instance.
- param request:
The underlying Starlette request.
- param path_params:
Path parameters extracted from the URL.
- param method:
The HTTP method.
- param path:
The request path.
- param query_params:
Query parameters.
- param headers:
HTTP headers.
- param body:
Request body.
- param client_ip:
Client IP address.
- apifrom.core.request.__getattr__(name)ο
Get an attribute from the underlying request.
- param name:
The name of the attribute.
- returns:
The attribute value.
- raises AttributeError:
If the attribute is not found.
- apifrom.core.request.body()ο
- :async:
Get the request body.
- returns:
The request body as bytes.
- apifrom.core.request.form()ο
- :async:
Get the request body as form data.
- returns:
The request body parsed as form data.
- apifrom.core.request.get_param(name, default=None)ο
Get a parameter from the request.
This method looks for the parameter in path parameters, query parameters, and then the request body (in that order).
- param name:
The name of the parameter.
- param default:
The default value to return if the parameter is not found.
- returns:
The parameter value, or the default value if not found.
- apifrom.core.request.json()ο
- :async:
Get the request body as JSON.
- returns:
The request body parsed as JSON.
- raises ValueError:
If the request body is not valid JSON.