fregelab/chinook

Q: Request parameter handling

Closed this issue · 8 comments

Dierk commented

How are request parameters handled? Are they converted from Strings to values (like Spring does)?

At the moment they are retrieved as strings. Mappers or any mechanism to convert parameters to anything else are not included in Chinook.

My idea about Chinook is to keep it to the minimum. Anything else (validation, mapping...) should be provided by other Frege/Java libraries.

Dierk commented

I feel it would be helpful to at least parse the request parameters into an immutable data structure (map) of String keys and entries that are either String or list of entry or maps from String to entry.

Agree, making the request an immutable data structure is definitely something I'm planning to do. 👍

I'm actually migrating the mutable Spark request to an immutable data structure. I have implemented data types for headers, query parameters and path parameters:

data Header     = Header      (String, Maybe String)
data QueryParam = QueryParam  (String, [String])
data PathParam  = PathParam   (String, Maybe String)

data IRequest   = IRequest    { hs  :: [Header], qps :: [QueryParam], pps :: [PathParam] } where

But now I'm wondering whether if it would be better to handle raw data types without the data type itself or to keep everything within data types and create functions to extract, modify data coming from a Header, QueryParam...

From a user point of view, I think it would be more friendly to extract a parameter like this:

param :: IO IRequest -> String -> [String]

Than this:

param :: IO IRequest -> String -> QueryParam

The same for headers, I think it is easier to use:

header :: IO IRequest -> String -> Maybe String

than:

header :: IO IRequest -> String -> Header

I'm not sure which way would be the best approach. Any ideas ?

Dierk commented

Two observations:
a) you may want to compare notes with @mmhelloworld who started work on https://github.com/mmhelloworld/fregelet. It feels like we have duplicated effort at least wrt the parameter handling.
b) you cannot get from an IO x type to a non-IO type ;-)

a) Nice :) I'll take a look at it thanks
b) Yes of course, you're right I just didn't pay attention while writing the signature :P

Please check last version and docs (http://januslynd.github.io/chinook/). I've made a first attempt to migrate request and response to data types.

Dierk commented

That looks great!