linnet-0.1.0.0: Lightweight library for building HTTP API

Safe HaskellNone
LanguageHaskell2010

Linnet.Bootstrap

Synopsis

Documentation

bootstrap :: forall (ct :: Symbol) m a. Endpoint m a -> Bootstrap m (Coproduct (Proxy ct) CNil) (HList '[Endpoint m a]) Source #

Create Bootstrap out of single Endpoint and some given Content-Type:

bootstrap @TextPlain (pure "foo")

serve :: forall (ct :: Symbol) cts es m a. Endpoint m a -> Bootstrap m cts (HList es) -> Bootstrap m (Coproduct (Proxy ct) cts) (HList (Endpoint m a ': es)) Source #

Add another endpoint to Bootstrap for purpose of serving multiple Content-Types with *different* endpoints

bootstrap @TextPlain (pure "foo") & server @ApplicationJson (pure "bar")

compile :: forall cts m es. Compile cts m es => Bootstrap m cts es -> ReaderT Request m Response Source #

Compile Bootstrap into ReaderT Request m Response for further combinations. Might be useful to implement middleware in context of the same monad m:

bootstrap @TextPlain (pure "foo") & compile

toApp :: (forall a. m a -> IO a) -> ReaderT Request m Response -> Application Source #

Convert ReaderT Request m Response into WAI Application

bootstrap @TextPlain (pure "foo") & compile & toApp id

The first parameter here is a natural transformation of Endpoints monad m into IO. In case if selected monad is IO already then id is just enough. Otherwise, it's a good place to define how to "start" custom monad for each request to come and convert it to IO.

As an example:

  • ReaderT RequestContext IO could be used to pass some data as local context for the request.
  • Some monad for logging (i.e. co-log)