apifrom.adapters.vercel

Vercel serverless functions adapter for APIFromAnything.

This module provides adapter functionality to integrate APIFromAnything with Vercel serverless functions.

Overview

Classes

Classes

class apifrom.adapters.vercel.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:

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.

apifrom.adapters.vercel.router

The router instance for managing routes.

Type:

Router

apifrom.adapters.vercel.middleware

List of middleware instances.

Type:

list

apifrom.adapters.vercel.debug

Whether to run in debug mode.

Type:

bool

apifrom.adapters.vercel.title

The title of the API.

Type:

str

apifrom.adapters.vercel.description

The description of the API.

Type:

str

apifrom.adapters.vercel.version

The version of the API.

Type:

str

apifrom.adapters.vercel.docs_url

The URL for the API documentation.

Type:

str

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.vercel.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.adapters.vercel._request

The underlying Starlette request.

apifrom.adapters.vercel.path_params

Path parameters extracted from the URL.

apifrom.adapters.vercel.query_params

Query parameters extracted from the URL.

apifrom.adapters.vercel.headers

HTTP headers.

apifrom.adapters.vercel.method

HTTP method.

apifrom.adapters.vercel.path

Request path.

apifrom.adapters.vercel._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.vercel.Response(content=None, status_code=200, headers=None, content_type='application/json')[source]
Parameters:
  • content (Any)

  • status_code (int)

  • headers (Optional[Dict[str, str]])

  • content_type (str)

Response class for APIFromAnything.

This class represents an HTTP response and provides methods for setting response data, status code, and headers.

apifrom.adapters.vercel.content

The response content.

apifrom.adapters.vercel.status_code

The HTTP status code.

apifrom.adapters.vercel.headers

HTTP headers.

apifrom.adapters.vercel.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.

class apifrom.adapters.vercel.VercelAdapter(app)[source]
Parameters:

app (apifrom.core.app.API)

Adapter for integrating APIFromAnything with Vercel serverless functions.

This adapter transforms Vercel serverless functions events into APIFromAnything requests and responses.

Example

```python from apifrom import API from apifrom.decorators import api from apifrom.adapters.vercel import VercelAdapter

app = API(title=”Vercel API”)

@api(app, route=”/api/hello”, method=”GET”) def hello(name: str = “World”) -> dict:

return {“message”: f”Hello, {name}!”}

# Create a Vercel adapter vercel_adapter = VercelAdapter(app)

# Export the handler function for Vercel handler = vercel_adapter.get_handler() ```

Initialize the Vercel adapter.

param app:

The APIFromAnything API instance

apifrom.adapters.vercel._create_request(event)

Create an APIFromAnything request from a Vercel event.

param event:

The Vercel event object

returns:

An APIFromAnything request

apifrom.adapters.vercel._create_vercel_response(response)

Create a Vercel response from an APIFromAnything response.

param response:

The APIFromAnything response

returns:

A response object that Vercel can understand

apifrom.adapters.vercel.get_handler()

Get a handler function for Vercel serverless functions.

returns:

A function that can be used as a Vercel serverless function handler

rtype:

Callable

apifrom.adapters.vercel.handle(event, context=None)

Handle a Vercel serverless function event synchronously.

This is a wrapper around the async handler for compatibility with sync environments.

param event:

The Vercel event object

param context:

The Vercel context object (optional)

returns:

A response object that Vercel can understand