Registry#

Register resources on services.

class blacksmith.domain.registry.HttpResource(path: str, contract: Optional[Mapping[typing_extensions.Literal[HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS], Tuple[Type[blacksmith.domain.model.params.Request], Optional[Type[blacksmith.domain.model.params.Response]]]]])#

Represent a resource endpoint.

path: str#

Path that identify the resource.

contract: Optional[Mapping[typing_extensions.Literal[HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS], Tuple[Type[blacksmith.domain.model.params.Request], Optional[Type[blacksmith.domain.model.params.Response]]]]]#

A contract is a serialization schema for the request and there response.

class blacksmith.domain.registry.HttpCollection(path: str, contract: Optional[Mapping[typing_extensions.Literal['HEAD', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], Tuple[Type[blacksmith.domain.model.params.Request], Optional[Type[blacksmith.domain.model.params.Response]]]]], collection_parser: Optional[Type[blacksmith.domain.model.params.AbstractCollectionParser]])#
collection_parser: Optional[Type[blacksmith.domain.model.params.AbstractCollectionParser]]#

Override the default collection parlser for a given resource.

class blacksmith.domain.registry.ApiRoutes(path: Optional[str], contract: Optional[Mapping[typing_extensions.Literal[HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS], Tuple[Type[blacksmith.domain.model.params.Request], Optional[Type[blacksmith.domain.model.params.Response]]]]], collection_path: Optional[str], collection_contract: Optional[Mapping[typing_extensions.Literal[HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS], Tuple[Type[blacksmith.domain.model.params.Request], Optional[Type[blacksmith.domain.model.params.Response]]]]], collection_parser: Optional[Type[blacksmith.domain.model.params.AbstractCollectionParser]])#

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: Optional[blacksmith.domain.registry.HttpResource]#

Resource endpoint

collection: Optional[blacksmith.domain.registry.HttpCollection]#

Collection endpoint.

class blacksmith.domain.registry.Registry#

Store resources in a registry.

clients: MutableMapping[str, MutableMapping[str, blacksmith.domain.registry.ApiRoutes]]#
client_service: MutableMapping[str, Tuple[str, Optional[str]]]#
register(client_name: str, resource: str, service: str, version: Optional[str], path: Optional[str] = None, contract: Optional[Mapping[typing_extensions.Literal[HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS], Tuple[Type[blacksmith.domain.model.params.Request], Optional[Type[blacksmith.domain.model.params.Response]]]]] = None, collection_path: Optional[str] = None, collection_contract: Optional[Mapping[typing_extensions.Literal[HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS], Tuple[Type[blacksmith.domain.model.params.Request], Optional[Type[blacksmith.domain.model.params.Response]]]]] = None, collection_parser: Optional[Type[blacksmith.domain.model.params.AbstractCollectionParser]] = 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.

get_service(client_name: str) Tuple[Tuple[str, Optional[str]], Mapping[str, blacksmith.domain.registry.ApiRoutes]]#

Get the service associated for the client.

This method is used to find the endpoint of the service.

blacksmith.domain.registry.registry = <blacksmith.domain.registry.Registry object>#

Detault registry.

blacksmith.domain.registry.register(client_name: str, resource: str, service: str, version: Optional[str], path: Optional[str] = None, contract: Optional[Mapping[typing_extensions.Literal[HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS], Tuple[Type[blacksmith.domain.model.params.Request], Optional[Type[blacksmith.domain.model.params.Response]]]]] = None, collection_path: Optional[str] = None, collection_contract: Optional[Mapping[typing_extensions.Literal[HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS], Tuple[Type[blacksmith.domain.model.params.Request], Optional[Type[blacksmith.domain.model.params.Response]]]]] = None, collection_parser: Optional[Type[blacksmith.domain.model.params.AbstractCollectionParser]] = None) None#

Register a resource in a client in the default registry.

See blacksmith.domain.registry.Registry.register() for the signature.