Routes
API route implementation for odin-control.
This module implements an API route object used by odin-control to handle API-related requests.
Tim Nicholls, STFC Application Engineering Group
ApiRoute
Bases: Route
ApiRoute - API route object used to map handlers onto adapter for API calls.
Source code in src/odin_control/http/routes/api.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
__init__(enable_cors=False, cors_origin='*', api_version=None)
Initialize the ApiRoute object.
This constructor initialises the API route object, defining handlers for version, adapter list and adapter API calls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enable_cors
|
flag to enable CORS request support |
False
|
|
cors_origin
|
CORS allowed origins |
'*'
|
|
api_version
|
API version string |
None
|
Source code in src/odin_control/http/routes/api.py
adapter(subsystem)
Return adapter for subsystem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subsystem
|
subsystem to return adapter for |
required |
Returns:
| Type | Description |
|---|---|
|
adapter for subsystem |
cleanup_adapters()
Clean up state of registered adapters.
This calls the cleanup method present in any registered adapters, allowing them to clean up their state (e.g. connected hardware) in a controlled fashion at shutdown.
Source code in src/odin_control/http/routes/api.py
has_adapter(subsystem)
Determine if ApiRoute object has adapter for subsystem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subsystem
|
subsystem to check for adapter |
required |
Returns:
| Type | Description |
|---|---|
|
True of adapter present for subsystem |
Source code in src/odin_control/http/routes/api.py
initialize_adapters()
Initialize all the adapters after they have been registered by the route.
This calls the initialize method present in any registered adapters, passing the dictionary of listed adapters to each, for inter adapter communication.
Source code in src/odin_control/http/routes/api.py
register_adapter(adapter_config, fail_ok=True)
Register an API adapter with the APIRoute object.
Based on the adapter_config object passed in as an argument, this method attempts to load the specified module and create an instance of the adapter class to be used to handle requests to the API route on the appropriate path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter_config
|
AdapterConfig object for the adapter |
required | |
fail_ok
|
Allow the adapter import and registration to fail without raising an error |
True
|