fregelab / chinook

Tiny Frege web framework developed on top of sparkjava.com
http://fregelab.github.io/chinook/
Apache License 2.0
28 stars 4 forks source link

Q: Request parameter handling #3

Closed Dierk closed 8 years ago

Dierk commented 8 years ago

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

januslynd commented 8 years ago

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 8 years ago

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.

januslynd commented 8 years ago

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

januslynd commented 8 years ago

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 8 years ago

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 ;-)

januslynd commented 8 years ago

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

januslynd commented 8 years ago

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 8 years ago

That looks great!