Services¶
-
class
stackinabox.services.service.StackInABoxService(name)¶ Stack-In-A-Box Service interface.
StackInABoxService provides the functionality and interface to build a service that is compliant with the requirements of Stack-In-A-Box.
-
base_url¶ Base URI utilized for anything managed by this instance.
-
create_route(uri, sub_service)¶ Create the route for the URI.
Parameters: - uri – string - URI to be routed
- sub_service – boolean - is the URI for a sub-service
Returns: n/a
-
static
get_service_regex(service_url, sub_service)¶ Get the regex for a given service.
Parameters: - base_url – string - Base URI
- service_url – string - Service URI under the Base URI
- sub_service – boolean - is the Service URI for a sub-service?
Returns: Python Regex object containing the regex for the Service
-
static
is_regex()¶ Is the provided URI a regex?
Returns: boolean
-
register(method, uri, call_back)¶ Register a class instance function to handle a request.
Parameters: - method – string - HTTP Verb
- uri – string - URI for the request
- call_back – class instance function that handles the request
Returns: n/a
-
register_subservice(uri, service)¶ Register a class instance to handle a URI.
Parameters: - uri – string - URI for the request
- service – StackInABoxService object instance that handles the request
Returns: n/a
-
request(method, request, uri, headers)¶ Handle the supplied request on the specified routing URI.
Parameters: - method – string - HTTP Verb
- request – request object describing the HTTP request
- uri – URI of the reuqest
- headers – case-insensitive headers dict
Returns: tuple - (int, dict, string) containing: int - the http response status code dict - the headers for the http response string - http string response
-
reset()¶ Reset the service to its’ initial state.
-
sub_request(method, request, uri, headers)¶ Handle the supplied sub-service request on the specified routing URI.
Parameters: - method – string - HTTP Verb
- request – request object describing the HTTP request
- uri – URI of the reuqest
- headers – case-insensitive headers dict
Returns: tuple - (int, dict, string) containing: int - the http response status code dict - the headers for the http response string - http string response
-
try_handle_route(route_uri, method, request, uri, headers)¶ Try to handle the supplied request on the specified routing URI.
Parameters: - route_uri – string - URI of the request
- method – string - HTTP Verb
- request – request object describing the HTTP request
- uri – URI of the reuqest
- headers – case-insensitive headers dict
Returns: tuple - (int, dict, string) containing: int - the http response status code dict - the headers for the http response string - http string response
-
static
validate_regex(sub_service)¶ Is the regex valid for StackInABox routing?
Parameters: - regex – Python regex object to match the URI
- sub_service – boolean for whether or not the regex is for a sub-service
Raises: InvalidRouteRegexError if the regex does not meet the requirements.
-