apifrom.core.responseο
Response module for APIFromAnything.
This module defines the Response class and related utilities for handling HTTP responses.
Overviewο
Classes
ErrorResponseHTMLResponseJSONResponseRedirectResponseTextResponse
Classesο
- 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.
- 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.
- 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.
- 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.
- class apifrom.core.response.Response(content=None, status_code=200, headers=None, content_type='application/json')[source]ο
Response class for APIFromAnything.
This class represents an HTTP response and provides methods for setting response data, status code, and headers.
- apifrom.core.response.contentο
The response content.
- apifrom.core.response.status_codeο
The HTTP status code.
- apifrom.core.response.headersο
HTTP headers.
- apifrom.core.response.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.
- apifrom.core.response.from_dict(data)ο
- :classmethod:
Create a Response instance from a dictionary.
- param data:
The dictionary containing response data.
- returns:
A new Response instance.
- apifrom.core.response.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.
- apifrom.core.response.to_dict()ο
Convert the response to a dictionary.
- returns:
A dictionary representation of the response.
- apifrom.core.response.to_starlette_response()ο
Convert to a Starlette response.
- returns:
A Starlette response.
- 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.