scistag.webstag.server.class_service.WebClassService¶
- class WebClassService(service_name, url_prefix, support_flask=False)[source]¶
Bases:
WebStagServiceThe WebStagClassService allows publishing a simple Python class as web service.
If not passed otherwise in
add_class()the service’s route will be the lower camel-case variant of the class’ name, the same applies to all member functions.e.g. MyTestClass.print_hello_world will be published as /myTestClass/helloWorld.
Functions beginning with a
get_will automatically be interpreted as getter functions and published as such. The ``get_` name component will automatically be stripped upon publishing.Example. MyClass.get_item_count -> /myClass/itemCount.
- Parameters
service_name (
str) – The name under which the service is registered. Just has to be unique.url_prefix (
str) –The url_prefix under which the service will be registered.
e.g. “myService” will be hosted under the url myService/myClass/myMethod.
support_flask – Defines if the service shall be configured for flask
Methods
Registers a new class type
Receives all calls to this service if
setup_wrapper_blueprint()was used to configure this service.Assigns a blueprint which will provide this service in flask
Setups a Flask blueprint for this service which receives all calls to the url_suffix root at which this service was registered.
Attributes
__dict____doc____module____weakref__list of weak references to the object (if defined)
- add_class(class_type, service_name=None, multithread=False, parameters=None)[source]¶
Registers a new class type
- Parameters
class_type –
The class to register.
A singleton object of the class will be created upon first use.
service_name (str | None) – The name under which the service shall be reached
multithread (bool) – Defines if the created object is multi-thread secure. If it’s not than the service will not allow more than one caller at the same time.
parameters (dict | None) –
The parameters to be passed to the object’s constructor.
Note that these value will be kept and passed on upon first use of the object’s services.
- handle_unified_request(request)[source]¶
Receives all calls to this service if
setup_wrapper_blueprint()was used to configure this service.- Parameters
request (
WebRequest) – The request - unifying incoming Flask and Fast API calls.- Return type
- Returns
The response - which is being converted back to a Flask and/or FastAPI response.
- set_service_blueprint(service)¶
Assigns a blueprint which will provide this service in flask
- Parameters
service (
Blueprint) – The blueprint forwarding its requests to us
- setup_wrapper_blueprint()¶
Setups a Flask blueprint for this service which receives all calls to the url_suffix root at which this service was registered.
You can then handle all calls to this base url suffix and via the unified handle_unified_request method. :return:
- reg_params¶
Additional registration parameters to be passed to register_blueprint
- service_name¶
The service’s name