~pepe/chidi

Your soulmate
a2aaf645 — Josef Pospíšil 2 years ago
Code design
16f1ca68 — Josef Pospíšil 2 years ago
Move to spork/json
caa2ad51 — Josef Pospíšil 2 years ago
Add broken pipe to closed-err?

refs

master
browse  log 

clone

read-only
https://git.sr.ht/~pepe/chidi
read/write
git@git.sr.ht:~pepe/chidi

You can also use your local clone with git send-email.

#Chidi

Our attempt at creating http kit for Good Place with Janet programming language.

#Aim

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.

#Bits and pieces

There are four modules in order of importance:

#Server

You can 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.

#Middleware

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.

Starting with parse-request which returns string transformed into Janet table with keys known from other places, such as :method, :uri or :body. One very important action is routing with drive middleware. The configuration is again Janet table, and it implicitly uses parse-request middleware.

Second group are higher level transformation of both http request and response. There is query-params which convert query string to the table, urlencoded which extracts data from form request, multipart for parsing multipart encoded requests, 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. You can quard-methods so for example only GET http method gets through, or 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.

#Special thanks

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!

Do not follow this link