apifrom.core.response ===================== Response module for APIFromAnything. This module defines the Response class and related utilities for handling HTTP responses. .. py:currentmodule:: apifrom.core.response Overview -------- **Classes** * :py:class:`ErrorResponse` * :py:class:`HTMLResponse` * :py:class:`JSONResponse` * :py:class:`RedirectResponse` * :py:class:`Response` * :py:class:`TextResponse` Classes ------- .. py:class:: ErrorResponse(message, status_code = 400, error_code = None, details = None, headers = None):bases: JSONResponse Error response for APIFromAnything. This class represents an HTTP error response with JSON content. Initialize a new ErrorResponse instance. :param message: The error message. :param status_code: The HTTP status code. :param error_code: An optional error code. :param details: Additional error details. :param headers: HTTP headers. .. py:class:: HTMLResponse(content = '', status_code = 200, headers = None):bases: Response HTML response for APIFromAnything. This class represents an HTTP response with HTML content. Initialize a new HTMLResponse instance. :param content: The HTML content. :param status_code: The HTTP status code. :param headers: HTTP headers. .. py:class:: JSONResponse(content = None, status_code = 200, headers = None):bases: Response JSON response for APIFromAnything. This class represents an HTTP response with JSON content. Initialize a new JSONResponse instance. :param content: The response content. :param status_code: The HTTP status code. :param headers: HTTP headers. .. py:class:: RedirectResponse(url, status_code = 302, headers = None):bases: Response Redirect response for APIFromAnything. This class represents an HTTP redirect response. Initialize a new RedirectResponse instance. :param url: The URL to redirect to. :param status_code: The HTTP status code. :param headers: HTTP headers. .. py:class:: Response(content = None, status_code = 200, headers = None, content_type = 'application/json') Response class for APIFromAnything. This class represents an HTTP response and provides methods for setting response data, status code, and headers. .. attribute:: content The response content. .. attribute:: status_code The HTTP status code. .. attribute:: headers HTTP headers. .. attribute:: content_type The content type of the response. Initialize a new Response instance. :param content: The response content. :param status_code: The HTTP status code. :param headers: HTTP headers. :param content_type: The content type of the response. .. :: content .. :: content_type .. :: headers .. :: status_code .. method:: from_dict(data) :classmethod: Create a Response instance from a dictionary. :param data: The dictionary containing response data. :returns: A new Response instance. .. method:: set_cookie(key, value = '', max_age = None, expires = None, path = '/', domain = None, secure = False, httponly = False, samesite = 'lax') Set a cookie in the response. :param key: The cookie name. :param value: The cookie value. :param max_age: The maximum age of the cookie in seconds. :param expires: The expiration time of the cookie as a UNIX timestamp. :param path: The path for which the cookie is valid. :param domain: The domain for which the cookie is valid. :param secure: Whether the cookie should only be sent over HTTPS. :param httponly: Whether the cookie should be accessible only via HTTP. :param samesite: The SameSite attribute of the cookie. .. method:: to_dict() Convert the response to a dictionary. :returns: A dictionary representation of the response. .. method:: to_starlette_response() Convert to a Starlette response. :returns: A Starlette response. .. py:class:: TextResponse(content = '', status_code = 200, headers = None):bases: Response Text response for APIFromAnything. This class represents an HTTP response with plain text content. Initialize a new TextResponse instance. :param content: The text content. :param status_code: The HTTP status code. :param headers: HTTP headers.