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]
Parameters:
  • request (Optional[starlette.requests.Request])

  • path_params (Optional[dict[Any, Any]])

  • method (Optional[str])

  • path (Optional[str])

  • query_params (Optional[dict[Any, Any]])

  • headers (Optional[dict[Any, Any]])

  • body (Optional[Union[str, bytes]])

  • client_ip (Optional[str])

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.