bareasgi_rest
module bareasgi_rest ¶
Summary¶
Enhanced REST support for bareASGI
function bareasgi_rest.add_swagger_ui ¶
Summary¶
Add the Swagger UI
class RestHttpRouter(BasicHttpRouter) ¶
Summary¶
Initialise the REST router
Description¶
Here is an example of how to use the router.
from bareasgi import Application
from bareasgi_rest import RestHttpRouter, add_swagger_ui
router = RestHttpRouter(
None,
title="Books",
version="1",
description="A book api",
base_path='/api/1',
tags=[
{
'name': 'Books',
'description': 'The book store API'
}
]
)
app = Application(http_router=router)
add_swagger_ui(app)
Parameters¶
not_found_response: HttpResponseThe response sent when a route is not found
title: strThe title of the swagger documentation
version: strThe version of the exposed API
description: Optional[str] (optional)The API description. Defaults to None.
base_path: str (optional)The base path of the API. Defaults to ''.
consumes: Optional[DictConsumes] (optional)A map of media types and deserializers. Defaults to DEFAULT_CONSUMES.
produces: Optional[DictProduces] (optional)A map of media types and serializers. Defaults to DEFAULT_PRODUCES.
tags: Optional[List[Mapping[str, Any]]] (optional)The available tags. Defaults to None.
swagger_base_url: Optional[str] (optional)The base url for the swagger CDN. Defaults to DEFAULT_SWAGGER_BASE_URL.
typeface_url: Optional[str] (optional)The base url for the typeface. Defaults to DEFAULT_TYPEFACE_URL.
config: Optional[SwaggerConfig] (optional)The swagger configuration. Defaults to None.
serializer_configs: Optional[DictSerializerConfig] (optional)The serializer configuration for content. Defaults to DEFAULT_SERIALIZER_CONFIG.
arg_serializer_config: SerializerConfig (optional)The serializer configuration for arguments. Defaults to DEFAULT_JSON_SERIALIZER_CONFIG.
arg_deserializer_factory: ArgDeserializerFactory (optional)The deserializer configuration for arguments. Defaults to DEFAULT_ARG_DESERIALIZER_FACTORY.
method RestHttpRouter.add ¶
Summary¶
Add an HTTP request handler
Parameters¶
methods: AbstractSet[str]The supported HTTP methods.
path: strThe path.
callback: HttpRequestCallbackThe request handler.
method RestHttpRouter.add_rest ¶
Summary¶
Register a callback to a method and path
Parameters¶
methods: AbstractSet[str]The set of methods
path: strThe path
callback: RestCallbackThe callback
consumes: List[bytes] (optional)The content media type. Defaults to b'application/json'.
produces: List[bytes] (optional)The accept media type. Defaults to b'application/json'.
collection_format: str (optional)The format of repeated values. Defaults to DEFAULT_COLLECTION_FORMAT.
tags: Optional[List[str]] (optional)A list of tags. Defaults to None.
status_code: int (optional)The ok status code. Defaults to 200.
status_description: str (optional)The ok status message. Defaults to 'OK'.
serializer_config: Optional[DictSerializerConfig] (optional)The serializer configuration for content. Defaults to None.
arg_serializer_config: Optional[SerializerConfig] (optional)The serializer configuration for arguments. Defaults to None.
arg_deserializer_factory: Optional[ArgDeserializerFactory] (optional)The deserializer configuration for arguments. Defaults to None.
method RestHttpRouter.add_route ¶
Summary¶
Add a route to a callback for a method and path definition
Parameters¶
method: strThe method.
path_definition: PathDefinitionThe path definition
callback: HttpRequestCallbackThe callback
class SwaggerConfig ¶
Summary¶
The Swagger UI Configuration
Parameters¶
title: str (optional)The page title, defaults to "The REST API"
validator_url: Optional[str] (optional)The url of the validator, defaults to None
supported_submit_methods: Optional[List[str]] (optional)The supported submit methods, defaults to None
display_operation_id: bool (optional)Whether operation ids should be displayed, defaults to False
display_request_duration: bool (optional)Whether the duration of the request should be displayed, defaults to False
doc_expansion: str (optional)How the methods should be displayed, defaults to "list"
oauth2: Optional[SwaggerOauth2Config] (optional)Optional oauth2 config, defaults to None
serialize_key: Callable[[str], str] (optional)The function to serialize keys
deserialize_key: Callable[[str], str] (optional)The function to deserialize keys
class SwaggerOauth2Config ¶
Summary¶
Swagger Oauth2 config
Parameters¶
client_id: strThe client id
realm: strThe realm
app_name: strThe application name
redirect_url: strThe redirect url