Skip to content

Fundamental Concepts

Dawid Kraczkowski edited this page Feb 25, 2021 · 11 revisions

Chocs works around some concepts that might be familiar for most developers. This chapter touches those concepts and explains application flow.

Application flow

The following diagram show abstracted chocs's application flow. Presented flow works the same way across different environments (AWS, WSGI, etc).

Application Flow

Client performs a HTTP request to your application, this request is handled by the framework layer and gets transformed to chocs.HttpRequest instance. Transformed request is then passed to middleware layer which can amend application behaviour by for example modifying request contents and passing it to user defined controller. The controller must return chocs.HttpResponse instance as a processing output. Returned response is passed back to middleware layer. Middleware then passes (modified) response object back to framework layer and valid HTTP Response object is served to the client.

Application

Application is a core part of chocs. It takes care of interpreting and transformig requests, passing requests' path to router and executing middleware and controllers. chocs.Application class also provides simple interface to register controllers and assign route patterns to them, so when request is made it can be routed to corresponding controller.

Request

There are two types of request:

  • native request this type of request varies depending on the environment in which application runs (aws, wsgi, etc..), and is hidden from usage
  • internal request which is an instance of chocs.HttpRequest and provides abstraction for native http requests

Chocs task is to understand native request and transform it into an instance of chocs.HttpRequest, this transformation happens automatically.

More about request and its usage is available here.

Response

Routing

Controller

Middleware