servant-0.2

Safe HaskellNone
LanguageHaskell2010

Servant.API.Get

Synopsis

Documentation

data Get a Source

Endpoint for simple GET requests. Serves the result as JSON.

Example:

type MyApi = "books" :> Get [Book]

Instances

VLinkHelper * (Get x) 
ToJSON result => HasServer (Get result)

When implementing the handler for a Get endpoint, just like for Delete, Post and Put, the handler code runs in the EitherT (Int, String) IO monad, where the Int represents the status code and the String a message, returned in case of failure. You can quite handily use left to quickly fail if some conditions are not met.

If successfully returning a value, we just require that its type has a ToJSON instance and servant takes care of encoding it for you, yielding status code 200 along the way.

Typeable (* -> *) Get 
type Server (Get result) = EitherT (Int, String) IO result