Handlers
API request handler for odin-control.
This module implements the API request handler used by odin-control to pass API calls to adapters.
Tim Nicholls, STFC Detector Systems Software Group.
ApiError
ApiHandler
Bases: CorsRequestHandler
API handler to transform requests into appropriate adapter calls.
This handler maps incoming API requests onto the appropriate calls to methods in registered adapters. HTTP GET, PUT, POST, DELETE and OPTIONS verbs are supported. The handler also enforces a uniform response with the appropriate Content-Type header.
Source code in src/odin_control/http/handlers/api.py
delete(subsystem, path='')
async
Handle an API DELETE request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subsystem
|
subsystem element of URI, defining adapter to be called |
required | |
path
|
remaining URI path to be passed to adapter method |
''
|
Source code in src/odin_control/http/handlers/api.py
get(subsystem, path='')
async
Handle an API GET request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subsystem
|
subsystem element of URI, defining adapter to be called |
required | |
path
|
remaining URI path to be passed to adapter method |
''
|
Source code in src/odin_control/http/handlers/api.py
post(subsystem, path='')
async
Handle an API POST request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subsystem
|
subsystem element of URI, defining adapter to be called |
required | |
path
|
remaining URI path to be passed to adapter method |
''
|
Source code in src/odin_control/http/handlers/api.py
put(subsystem, path='')
async
Handle an API PUT request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subsystem
|
subsystem element of URI, defining adapter to be called |
required | |
path
|
remaining URI path to be passed to adapter method |
''
|
Source code in src/odin_control/http/handlers/api.py
respond(response)
Respond to an API request.
This method transforms an ApiAdapterResponse object into the appropriate request handler response, setting the HTTP status code and content type for a response to an API request and validating the content of the response against the appropriate type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
ApiAdapterResponse object containing response |
required |
Source code in src/odin_control/http/handlers/api.py
validate_api_request(func)
Validate an API request to the ApiHandler.
This decorator checks that, if API versioning is enabled, the version element of the URI of a request is correct and that the subsystem is registered with the application dispatcher; it responds with a 400 error if not.