Typed HTTP APIs (Effect's effect/http-api): declare endpoints once,
serve them, call them with a derived client and document them with
OpenAPI.
endpoint:get/post/ ... make anHttpApiEndpointfrom its path and the schemas of its params, query, payload, headers, successes and errorsgroup:HttpApiGroup, a class whose attributes are endpointsapi:HttpApi, groups under one identifierbuilder:group(api, Users, build)is the layer of a group's handlers,layer(api)adds every group's routes to the routerclient:make(api)derives a client whose methods are typed by the declarations;test: one calling the handlers in memoryschema: response statuses, encodings, streams (SSE, NDJSON, bytes), upgrades and response headers;error: the status errorsmiddleware,security:HttpApiMiddlewareand the credentials it decodes (bearer, basic, API keys)openapi: the OpenAPI 3.1 document of an API;swaggerandscalarserve it as documentation pages
::
class Users(HttpApiGroup, identifier="users"):
get_user = endpoint.get(
"getUser", "/users/:id", params=S.Struct(UserParams), success=User, error=NotFound
)
api = HttpApi.make("app").add(Users)
UsersLive = builder.group(api, Users, lambda h: h.handle(Users.get_user)(get_user))
api_client = yield from client.make(api)
user = yield from get_group(api_client, Users).get_user(params={"id": 1})Re-exports#
- From
pyfect.http_api.api:HttpApi - From
pyfect.http_api.client:Client,get_group - From
pyfect.http_api.endpoint:HttpApiEndpoint - From
pyfect.http_api.error:HttpApiPayloadTooLarge,HttpApiSchemaError - From
pyfect.http_api.group:HttpApiGroup - From
pyfect.http_api.middleware:HttpApiMiddleware - From
pyfect.http_api.security:HttpApiSecurity