Our attempt at creating http kit for Good Place with Janet programming language.
The main aim of this library is to provide programmer with the all the main bits and pieces for creating her own http server written with Janet. Parts are described in the next chapter of this document. If you are brave, you can jump right to the examples directory. More information will be soon in the TECH document.
Another smaller, yet profound aim is to use the Janet
ev module. To get
more practial experience, and to test the ideas related to
ev. Here I must
say, I am more than happy with what I have found.
There are four modules in order of importance:
start new server with handler function and optional host and port.
Handler function needs to be able to receive the string of the http request and
returns the string with http response.
As http strings are not that funny to work with, Chidi helps with most of the
tasks. Middlewares are usuably functions which take argument of
next-middleware which must be function to next in the processing chain.
Middlewares can be chained, but only in order respecting their functionality.
Middleware must return the function with only argument http request and return
the call to next middleware or http response string.
parse-request which returns string transformed into Janet
table with keys known from other places, such as
One very important action is routing with
drive middleware. The configuration
is again Janet table, and it implicitly uses
Second group are higher level transformation of both http request and response.
query-params which convert query string to the table,
which extracts data from form request,
multipart for parsing multipart encoded
cookies for parsing cookies' headers and
json->body which parses
body in the json document notation.
Third group contains middlewares for deciding on the properties of the request.
quard-methods so for example only GET http method gets through,
guard-mime similarily for the http mime type. The
dispatch can call
different functions based on http method, again defined by the table.
The last two middlewares are
journal for simple request logging to stdout, and
stoic for serving static assets from in the directory provided as the first
argument to its call.
Definitely @bakpakin for Janet and EJIFG.
As with many projects of mine, Chidi is owning a lot of its design and aim at simplicity to @sogaiu. Thank you sir, without you I am not sure I can make this.
I also owe a lot of to the @swlkr for his great work on halo2 and osprey. Thank you Sean!