PLBA2-4. Доработка регистрации http эндпоинтов
This commit is contained in:
+49
-4
@@ -12,10 +12,55 @@ Register `WorkerDefinition` objects in a `WorkerRegistry`, pass the registry and
|
||||
`ApplicationRuntime`. Register non-worker checks in `HealthContributorRegistry`
|
||||
and connect it to `HealthAggregator` with `RuntimeHealthInputProvider`.
|
||||
|
||||
Mount `ControlApi(runtime, health_aggregator)` in the application's ASGI host.
|
||||
The host owns the socket and listener; the adapter contributes `/health`,
|
||||
`/runtime/start`, `/runtime/stop`, and `/runtime/status` to that same listener.
|
||||
The application chooses when to start and stop the runtime.
|
||||
Register application endpoints as typed `HttpRoute` values when composing the
|
||||
ASGI application. The built-in routes and application handlers share the same
|
||||
`ControlApi` router and listener:
|
||||
|
||||
```python
|
||||
import json
|
||||
|
||||
from plba.http import ControlApi, HttpRoute
|
||||
|
||||
|
||||
async def get_order(scope, receive, send):
|
||||
body = json.dumps({"order_id": scope["path_params"]["order_id"]}).encode()
|
||||
await send(
|
||||
{
|
||||
"type": "http.response.start",
|
||||
"status": 200,
|
||||
"headers": [(b"content-type", b"application/json")],
|
||||
}
|
||||
)
|
||||
await send({"type": "http.response.body", "body": body})
|
||||
|
||||
|
||||
api = ControlApi(
|
||||
runtime,
|
||||
health_aggregator,
|
||||
application_routes=(
|
||||
HttpRoute("GET", "/api/v1/orders/{order_id}", get_order),
|
||||
),
|
||||
)
|
||||
```
|
||||
|
||||
The built-in API paths are:
|
||||
|
||||
- `GET /api/v1/health`
|
||||
- `POST /api/v1/runtime/start`
|
||||
- `POST /api/v1/runtime/stop`
|
||||
- `GET /api/v1/runtime/status`
|
||||
|
||||
Application route templates must also start with `/api/v{version}/`, where
|
||||
`{version}` is a positive integer such as `v1`. Named path segments are
|
||||
available in `scope["path_params"]`, and the application handler owns its
|
||||
response.
|
||||
|
||||
For platform access, the public request path is
|
||||
`/{service-name}/api/v{version}/...`. Caddy selects the service upstream and
|
||||
removes `/{service-name}` before proxying, so the application receives the
|
||||
internal `/api/v{version}/...` path. The application host still owns one
|
||||
socket and listener; PLBA does not start a separate HTTP server. The
|
||||
application chooses when to start and stop the runtime.
|
||||
|
||||
## Configuration and settings
|
||||
|
||||
|
||||
Reference in New Issue
Block a user