apifrom.adapters.netlify
Netlify Functions adapter for APIFromAnything.
This module provides adapter functionality to integrate APIFromAnything with Netlify Functions.
Overview
Classes
Classes
- class apifrom.adapters.netlify.API(debug=False, title='APIFromAnything API', description='API created with APIFromAnything', version='1.0.0', docs_url='/docs', openapi_config=None, swagger_ui_config=None, enable_docs=True)[source]
- Parameters:
debug (bool)
title (str)
description (str)
version (str)
docs_url (str)
openapi_config (apifrom.docs.openapi.OpenAPIConfig | None)
swagger_ui_config (apifrom.docs.swagger_ui.SwaggerUIConfig | None)
enable_docs (bool)
Main application container for APIFromAnything.
This class serves as the central registry for all API endpoints, middleware, and configuration. It provides methods for registering endpoints, middleware, and starting the server.
Initialize a new API instance.
- param debug:
Whether to run in debug mode.
- param title:
The title of the API.
- param description:
The description of the API.
- param version:
The version of the API.
- param docs_url:
The URL for the API documentation.
- param openapi_config:
Configuration for OpenAPI documentation.
- param swagger_ui_config:
Configuration for Swagger UI.
- param enable_docs:
Whether to enable API documentation.
- class apifrom.adapters.netlify.NetlifyAdapter(app)[source]
- Parameters:
app (apifrom.core.app.API)
Adapter for integrating APIFromAnything with Netlify Functions.
This adapter transforms Netlify Functions events into APIFromAnything requests and responses.
Example
```python from apifrom import API from apifrom.decorators import api from apifrom.adapters.netlify import NetlifyAdapter
app = API(title=”Netlify API”)
@api(app, route=”/.netlify/functions/api/hello”, method=”GET”) def hello(name: str = “World”) -> dict:
return {“message”: f”Hello, {name}!”}
# Create a Netlify adapter netlify_adapter = NetlifyAdapter(app)
# Export the handler function for Netlify Functions def handler(event, context):
return netlify_adapter.handle(event, context)
Initialize the Netlify adapter.
- param app:
The APIFromAnything API instance
- apifrom.adapters.netlify._create_netlify_response(response)
Create a Netlify response from an APIFromAnything response.
- param response:
The APIFromAnything response
- returns:
A response object that Netlify can understand
- apifrom.adapters.netlify._create_request(event)
Create an APIFromAnything request from a Netlify event.
- param event:
The Netlify event object
- returns:
An APIFromAnything request
- apifrom.adapters.netlify._handle_async(event, context)
- :async:
Handle a Netlify Functions event asynchronously.
- param event:
The Netlify event object
- param context:
The Netlify context object
- returns:
A response object that Netlify can understand
- apifrom.adapters.netlify.handle(event, context)
Handle a Netlify Functions event.
- param event:
The Netlify event object
- param context:
The Netlify context object
- returns:
A response object that Netlify can understand
- class apifrom.adapters.netlify.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.adapters.netlify._request
The underlying Starlette request.
- apifrom.adapters.netlify.path_params
Path parameters extracted from the URL.
- apifrom.adapters.netlify.query_params
Query parameters extracted from the URL.
- apifrom.adapters.netlify.headers
HTTP headers.
- apifrom.adapters.netlify.method
HTTP method.
- apifrom.adapters.netlify.path
Request path.
- apifrom.adapters.netlify._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.
- class apifrom.adapters.netlify.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.adapters.netlify.content
The response content.
- apifrom.adapters.netlify.status_code
The HTTP status code.
- apifrom.adapters.netlify.headers
HTTP headers.
- apifrom.adapters.netlify.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.