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 and Markdown conversion service for collective.html2blocks.
Provides API endpoints for converting HTML or Markdown content to Volto blocks and block layout information. Includes endpoints for both simple block conversion and full Volto layout.
Example
POST /html
POST /markdown
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.MarkdownBody[source]#
Request body model for Markdown to blocks conversion.
- Variables:
markdown -- The Markdown content to convert.
converter -- The type of conversion to perform (default is
slate).
- 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 or Markdown to Volto blocks conversion with layout.
- Variables:
html -- The HTML or Markdown content to convert.
format -- The format of
html, eitherhtml(default) ormarkdown.default_blocks -- Default blocks to include.
additional_blocks -- Additional blocks to include.
- 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"}'
- async collective.html2blocks.services.html.convert_markdown(body: MarkdownBody) list[VoltoBlock][source]#
Convert Markdown to blocks.
Converts the provided Markdown content to a list of Volto blocks using the specified converter.
- Parameters:
body -- Request body containing Markdown and converter type.
- Returns:
The converted blocks.
- Raises:
HTTPException -- If an unsupported converter is specified.
Example
curl -X POST /markdown -d '{"markdown": "# Hello", "converter": "slate"}'
- collective.html2blocks.services.html.convert_to_volto(body: VoltoBody) VoltoBlocksInfo[source]#
Convert HTML or Markdown to Volto blocks and return blocks information.
Converts the provided content to a Volto blocks structure, including block layout. The
formatfield tells whether the content is HTML or Markdown.- Parameters:
body -- Request body containing the content, its format and block lists.
- Returns:
Information about the converted Volto blocks and layout.
Example
curl -X POST /volto -d '{"html": "<p>Hello</p>"}' curl -X POST /volto -d '{"html": "# Hello", "format": "markdown"}'
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": "..."}