Good Place library: Chidi

In the Good Place series, Chidi is one of the main character. It is main character's soulmate. Professor of the ethics who has problems with making decisions.

General

Chidi is the framework for creating application based on the http protocol. It has very simple http server based on the ev supervisors and fibers. It brings very nice performance characteristics and modularity.

Structure

In contrast to other Janet web frameworks the core works only with strings of the request and response. Everything else is solved by the middleware. From parsing request (by Janet's PEG) to contructing response (by printing to buffer).

Middleware

Right now there are these middleware:

  • Parsing of the request string into table.
  • Routing based on the pretty URL.
  • Converting to and from JSON in the body.
  • Guarding http methods.
  • Guarding accepted mime types.
  • Parsing query params
  • Dispatching based on the http method.
  • Serving static files.
  • Parsing urlencoded data from forms.
  • Parsing multipart data from forms.
  • Parsing cookies from headers

Response

Another module in the library is the response, which helps with creating, you guessed it, http responses. The most important is http function, which transforms the response table, used for middleware communication, into response string. On top of this function other specific response functions are implemented. For example success with status code 200, or not-found with status code 404.

Next there are couple of utility function for adding information to the response table. content-type and cookies for generating right header. Another are functions for rendering response body ->json for encoding json response and page for rendering html from the Temple template.

Last function in the response module is default-supervisor used in the server for supervising the creation and handling the connection.

Package: chidi Good Place 2021 All rights rejected