Track

Difference between version 1 and 2 - Previous - Next
A work in progress library for making a small web framework. Heavily inspired by the Elixir Phoenix framework request pipelining and routing


**Design**

   * Functional: most functions will transform a dict containing the information about the request and response.
   * Composable: it should be possible to combine request dict transformers in arbitrary order. This makes it possible to pick and choose parts of the "framework" and make it easy to extend. 
   * Prefix based: All defined callbacks are treated as prefixes.   * Re-usable: The transformers should be usable with any dict of the right structure. The router could be useful in other contexts than web servers and should be usable in that way.



**Components**


****Server****

Libraries of server connectors to convert the incoming request to a dict with the required parts correctly filled. For example socket should contain the client socket and path the query path.


****Router****

The router library takes a request dict and takes the path element an a routes list. It will then determine which route matches and call the associated prefix command with the request dict as last parameter (or without if the prefix start with !)

While matching the route, parts which start with @ or : will match anything and the matched part will be stored in the req dict as params. The difference between @ and : is that @ will also match any following slashes.

Example:

****Track****

Library of transformer functions which take a dict and perform useful transformations and side effects. For example mirroring an additional http request to the client.

Also contains helper functions to extract parts of the request dict without assuming the structure. For example `[@p $req name]` to get the name parameter from the request.


======
set routes {
    /ivi/:id                    ivi::handler
    /ivi/:id/:subresource       ivi::handler
    /svi/:vin                   svi::handler
    /soi/:id                    soi::handler
    /vicci/ihdcc/:code          {vicci::handler ihdcc}
    /vicci/dcc/:code            {vicci::handler dcc}
    /css/default.css            {track::asset default.css text/css}
    /                           {track::md index.md}
    /console                        {!console show}
    /exit                        {!exit}
    /vagbearer                  vagbearer::handler
    @rest                       track::debug_req
}
======