Application module reference¶
Contains core application structure for Micro.Web.
- class micro.web.app.Micro[source]¶
Micro is an entity which is in charge of routing configuration for our application and exception handling.
- default_error_handler(exception_instance, request)[source]¶
Default error handler.
Parameters: - exception_instance (Exception) – Instance of the exception to handle
- request (micro.core.request.Request) –
Returns:
- handle_error(e, request, endpoint_name)[source]¶
Error handler.
Parameters: - e – Exception happened while processing request
- request – micro.web.request.Request instance
- endpoint_name – Name of endpoint which produced the request
Returns:
- instance[source]¶
An instance of resource which is bound to this app, or None if app initialized not in resource scope.
- make_handler(*args, **kwargs)[source]¶
Make a protocol factory which compatible with asyncio.loop.create_server.
Returns:
- mount(prefix, resource)[source]¶
Mount the resource and maps all its routes to be accessible within prefix.
Parameters: - prefix (str) – A string prefix, which may start with “/” (auto-prepended if not)
- resource – A resource - an object which holds instance of Micro in its scope.
- route(url, method='*', endpoint=None)[source]¶
Wrap the function to make it accessible via URL.
Parameters: - url (str or regular expression) – aiohttp routing expression
- method (string) – HTTP method which should be passed onto micro.web.app.Router.add_route
- endpoint (str) – Route identifier which is used internally to maintain the state of routes. Endpoints should be unique across the application. Defaults to wrapped function name.
- run(host='0.0.0.0', port=7000, name=None, configure_logging=True, socket_family=<AddressFamily.AF_UNSPEC: 0>)[source]¶
A “run” handler, primarily for debugging purposes. This is only called when the server is started without gunicorn.
Parameters: - host – A host where to bind. Probably either ‘0.0.0.0’ or ‘localhost’.
- port – A port where to bind
- name – Service name to use in logging. If none, tries to discover it from gunicorn app name.
- configure_logging – Whether to apply default aiolocals logging configuration or not
:param socket_family The socket family which will be passed to server socket constructor
- serve_endpoint(route, request, *args, **kwargs)[source]¶
Serve an application handler with care of matching the needed resource for methods as handlers.
Parameters: - route (aiohttp.web_urldispatcher.Route) – A route instance
- request (micro.core.request.Request) – A request instance
- set_debug(debug)[source]¶
Sets the debug mode.
Parameters: debug (bool) – Boolean indicating whether to run application in debug mode or not Returns:
- set_error_handler(status_code, callback)[source]¶
Set error handler callback for specific response status code.
Parameters: - status_code – status code
- callback – error handler function