Registry¶
Register resources on services.
- class blacksmith.domain.registry.HttpResource(path: str, contract: Mapping[Literal['HEAD', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], tuple[Any, type[Response] | None]] | None)¶
Represent a resource endpoint.
- path: str¶
Path that identify the resource.
- class blacksmith.domain.registry.HttpCollection(path: str, contract: collections.abc.Mapping[Literal['HEAD', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], tuple[Any, type[blacksmith.domain.model.params.Response] | None]] | None, collection_parser: type[blacksmith.domain.model.params.AbstractCollectionParser] | None)¶
- collection_parser: type[AbstractCollectionParser] | None¶
Override the default collection parlser for a given resource.
- class blacksmith.domain.registry.ApiRoutes(path: str | None, contract: Mapping[Literal['HEAD', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], tuple[Any, type[Response] | None]] | None, collection_path: str | None, collection_contract: Mapping[Literal['HEAD', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], tuple[Any, type[Response] | None]] | None, collection_parser: type[AbstractCollectionParser] | None)¶
Store different routes for a type of resource.
Api may have a route for the resource and/or a route for collection. They both have distinct contract for every http method.
- resource: HttpResource | None¶
Resource endpoint
- collection: HttpCollection | None¶
Collection endpoint.
- class blacksmith.domain.registry.Registry¶
Store resources in a registry.
- client_service: MutableMapping[str, tuple[str, str | None]]¶
- register(client_name: str, resource: str, service: str, version: str | None, path: str | None = None, contract: Mapping[Literal['HEAD', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], tuple[Any, type[Response] | None]] | None = None, collection_path: str | None = None, collection_contract: Mapping[Literal['HEAD', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], tuple[Any, type[Response] | None]] | None = None, collection_parser: type[AbstractCollectionParser] | None = None) None ¶
Register the resource in the registry.
- Parameters:
client_name – used to identify the client in your code.
resource – name of the resource in your code.
service – name of the service in the service discovery.
version – version number of the service.
path – endpoint of the resource in the given service.
contract – contract for the resource, define request and response.
collection_path – endpoint of the resource collection in the given service.
collection_contract – contract for the resource collection, define request and response.
- blacksmith.domain.registry.registry = <blacksmith.domain.registry.Registry object>¶
Detault registry.
- blacksmith.domain.registry.register(client_name: str, resource: str, service: str, version: str | None, path: str | None = None, contract: Mapping[Literal['HEAD', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], tuple[Any, type[Response] | None]] | None = None, collection_path: str | None = None, collection_contract: Mapping[Literal['HEAD', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], tuple[Any, type[Response] | None]] | None = None, collection_parser: type[AbstractCollectionParser] | None = None) None ¶
Register a resource in a client in the default registry.
See
blacksmith.domain.registry.Registry.register()
for the signature.