linnet-0.4.0.1: Lightweight library for building HTTP API

Safe HaskellNone
LanguageHaskell2010

Linnet.Bootstrap

Synopsis

Documentation

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

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

bootstrap @TextPlain (pure "foo")

To enable Content-Type negotiation based on Accept header, use Coproduct :+: type operator to set the type:

bootstrap @(TextPlain :+: TextHtml) (pure "foo") -- in case of failed negotiation, text/html is picked as the last resort
bootstrap @(TextPlain :+: TextHtml :+: NotAcceptable406) (pure "foo") -- in case of failed negotiation, 406 is returned

serve :: forall ct cts es m a. Endpoint m a -> Bootstrap m cts (HList es) -> Bootstrap m (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") & serve @ApplicationJson (pure "bar")

compile :: forall cts m es. Compile cts m es => Bootstrap m cts es -> Compiled m Source #

Compile Bootstrap into Compiled that is just ReaderT for further combinations. Might be useful to implement middleware in context of the same monad m:

bootstrap @TextPlain (pure "foo") & compile

toApp :: forall m. NaturalTransformation m IO => Compiled m -> Application Source #

Convert Compiled into WAI Application

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

The constraint here is a natural transformation of Endpoints monad m into IO. In case if selected monad is IO already then provided instance is just enough. Otherwise, it's necessary define how to "start" custom monad for each request to come and convert it to IO as the instance of NaturalTransformation m IO.