purescript-hyper / hyper

Type-safe, statically checked composition of HTTP servers

Home Page:https://hyper.wickstrom.tech

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Polymorphic reading of request body

owickstrom opened this issue · comments

Should perhaps have been done in #6, but anyway:

The reading of a request body should be polymorphic in a type class, like:

class RequestBodyReader r m t where
  readBody :: Middleware m (Conn { body :: r, ... } ...) (Conn { body :: t, ... } ...)

... where r is the server-provided request body type, and t is some type required by the middleware chain. The node server could provide an instance:

instance nodeRequestBodyReader :: RequestBodyReader NodeRequestBody (Aff (avar :: AVAR ...)) String where
  readBody = ...

Without this, one cannot run a complete application, given that it parses request bodies with a server-specific middleware, together with the test server.