We recommend to check Trassir SDK manual before starting to work with own modules: https://www.dssl.ru/files/trassir/manual/en/sdk.html

Exthttp module provides the possibility to easily add new functions to Trassir SDK and helps to make modules with web interface (Automation 2.0). 

Module structure:

  • auth
    • login.py - Ready-made handlers for authorization.
    • user.py - User class, who will make the request.
  • core
    • app.py - Main class ExtHttpApp, that helps to register new handlers for SDK.

    • handlers.py - Some standard handlers.
    • module.py - Registration logic for module in Trassir automation (isn't used for API).

  • http
    • request.pyRequest object, instances of that object will be send to handlers.
    • response.py - Ready-made objects for request answers.
  • constant.py -  Some global constants.
  • utils.py -  Some helpful functions .


Handlers, that will be created by the script are available by a web-link, like: https://{server_ip}:{https_port}/{app_basename}/{route_path}, where:

  • server_ip - Trassir server address.
  • https_port - HTTPS server port. Can be changed in server settings, by default it's 8080. Trassir Client will use 8081.
  • app_basename - Basic module name, this name will be send as an argument in create_app function.
  • route_path - Separate handler web-link.

An example of simple module can be like this:

from exthttp import create_app, BaseHandler
from exthttp import http

app = create_app("ExampleApp")


@app.route("hello")
class HelloWorldHandler(BaseHandler):
    def get(self, request, *args, **kwargs):
        return http.JsonResponse({"message": "Hello World"})

What does this code do?

  1. Import of required dependencies:
    1. create_app - function for instance exthttp.core.app.ExtHttpApp creation.
      Uses app_basename as an argument, that will be in URL-request.
    2. BaseHandler - Parent class for all user handlers, that will work with route_path. Contains methods like GET/POST, which need to be created for making server answers on requests.
    3. http - contains ready-made objects for server answer: HttpResponse, HttpResponseNotFoundJsonResponse and others.
  2. Module creation with ExampleApp is a start for all next handlers like  https://{server_ip}:{https_port}/ExampleApp/{route_path} .
  3. Define new handler with route_path = "hello" .
    1. With app.route decorator we can set route_path
    2. Create a new handler, that will be inherited from Basehandler
    3. Redefine the get method, which will return  https://localhost:8080/s/ExampleApp/hello json answer on GET request.
      GET/POST methods take request as a required argument object.


  • Нет меток