collective.html2blocks.services#
FastAPI application setup for collective.html2blocks services.
This module initializes the FastAPI app, includes routers for healthcheck, HTML conversion, and info endpoints, and adds middleware for request timing.
Example
from collective.html2blocks.services import app
# Use with Uvicorn or other ASGI server
# uvicorn collective.html2blocks.services:app
- async collective.html2blocks.services.add_process_time_header(request: Request, call_next)[source]#
Middleware to attach
X-Process-Timeheader to each response.This middleware measures the time taken to process each HTTP request and adds the result as an
X-Process-Timeheader in the response.- Parameters:
request (Request) -- The incoming HTTP request.
call_next (Callable) -- The next ASGI handler to call.
- Returns:
The HTTP response with the process time header.
- Return type:
Response
Example
# Response headers will include ``X-Process-Time``
collective.html2blocks.services.healthcheck#
Healthcheck service for collective.html2blocks.
Provides a simple endpoint to verify that the API service is running and healthy.
Example
GET /ok
Response: {"status": "up"}
collective.html2blocks.services.html#
HTML conversion service for collective.html2blocks.
Provides API endpoints for converting HTML content to Volto blocks and block layout information. Includes endpoints for both simple block conversion and full Volto layout.
Example
POST /html
POST /volto
- class collective.html2blocks.services.html.HtmlBody[source]#
Request body model for HTML to blocks conversion.
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class collective.html2blocks.services.html.VoltoBody[source]#
Request body model for HTML to Volto blocks conversion with layout.
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- async collective.html2blocks.services.html.convert_html(body: HtmlBody) list[VoltoBlock][source]#
Convert HTML to blocks.
Converts the provided HTML content to a list of Volto blocks using the specified converter.
- Parameters:
body (HtmlBody) -- Request body containing HTML and converter type.
- Returns:
The converted blocks.
- Return type:
list[VoltoBlock]
- Raises:
HTTPException -- If an unsupported converter is specified.
Example
curl -X POST /html -d '{"html": "<p>Hello</p>", "converter": "slate"}'
- collective.html2blocks.services.html.convert_to_volto(body: VoltoBody) VoltoBlocksInfo[source]#
Convert HTML to Volto blocks and return blocks information.
Converts the provided HTML content to a Volto blocks structure, including block layout.
- Parameters:
body (VoltoBody) -- Request body containing HTML and block lists.
- Returns:
Information about the converted Volto blocks and layout.
- Return type:
VoltoBlocksInfo
Example
curl -X POST /volto -d '{"html": "<p>Hello</p>"}'
collective.html2blocks.services.info#
Info service for collective.html2blocks.
Provides the root endpoint with basic information about the API service, including its title, description, and version.
Example
GET /
Response: {"title": "Blocks Conversion Tool", ...}
- async collective.html2blocks.services.info.root() dict[source]#
Root endpoint for the HTML to Blocks service.
Returns a JSON object with service metadata including title, description, and version.
- Returns:
Service metadata.
- Return type:
Example
curl http://localhost:8000/{"title": "Blocks Conversion Tool", "description": "Convert HTML to blocks for use in Volto.", "version": "..."}