Skip to content

Documentation

Overview

md.http.server component provides psr.http.server contract implementation to build generic low-level web-application.

Implementation does not define the architecture design of high-level application how request will be handled, for example with Middleware or Dispatcher design pattern. It depends on high-level application implementation that will be injected.

Consider to look for md.http.server.lifecycle component that provides high-level application based on event model.

Architecture overview

Architecture overview

Install

pip install md.http.server --index-url https://source.md.land/python/

Usage

Request store

RequestStore class designed to store request which is currently in process in the thread.

Info

Typically, current request management is low-level application responsibility, it set request in RequestStore on processing start, and unset when processing is finished.

Notice

Data of this class is thread-aware, it means that each attribute has different values in diffrent threads.

Application

Application component is an implementation of psr.http.server.RequestHandlerInterface, designed as low-level application to , that means it responds for common request processing

Info

Application is designed as stateless and could be accessed from few threads simultaneously.

high-level application:

  1. convert response type

low-level application:

  1. log request/response facts
  2. set request identifier
  3. put request into store
  4. calls [high-level application]
  5. tracks response status
  6. handles any RuntimeException
  7. measure request processing time