<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"/><title>Servant.API.Get</title><linkhref="ocean.css"rel="stylesheet"type="text/css"title="Ocean"/><scriptsrc="haddock-util.js"type="text/javascript"></script><scripttype="text/javascript">//<![CDATA[
window.onload = function () {pageLoad();setSynopsis("mini_Servant-API-Get.html");};
</script></head><body><divid="package-header"><ulclass="links"id="page-menu"><li><ahref="src/Servant-API-Get.html">Source</a></li><li><ahref="index.html">Contents</a></li><li><ahref="doc-index.html">Index</a></li></ul><pclass="caption">servant-0.2: A family of combinators for defining webservices APIs and serving them</p></div><divid="content"><divid="module-header"><tableclass="info"><tr><th>Safe Haskell</th><td>None</td></tr><tr><th>Language</th><td>Haskell2010</td></tr></table><pclass="caption">Servant.API.Get</p></div><divid="synopsis"><pid="control.syn"class="caption expander"onclick="toggleSection('syn')">Synopsis</p><ulid="section.syn"class="hide"onclick="toggleSection('syn')"><liclass="src short"><spanclass="keyword">data</span><ahref="#t:Get">Get</a> a</li></ul></div><divid="interface"><h1>Documentation</h1><divclass="top"><pclass="src"><spanclass="keyword">data</span><aname="t:Get"class="def">Get</a> a <ahref="src/Servant-API-Get.html#Get"class="link">Source</a></p><divclass="doc"><p>Endpoint for simple GET requests. Serves the result as JSON.</p><p>Example:</p><pre>type MyApi = "books" :> Get [Book]</pre></div><divclass="subs instances"><pid="control.i:Get"class="caption collapser"onclick="toggleSection('i:Get')">Instances</p><divid="section.i:Get"class="show"><table><tr><tdclass="src"><ahref="Servant-Utils-Links.html#t:VLinkHelper">VLinkHelper</a> * (<ahref="Servant-API-Get.html#t:Get">Get</a> x)</td><tdclass="doc empty"> </td></tr><tr><tdclass="src"><ahref="https://hackage.haskell.org/package/aeson-0.8.0.2/docs/Data-Aeson-Types.html#t:ToJSON">ToJSON</a> result =><ahref="Servant-Server.html#t:HasServer">HasServer</a> (<ahref="Servant-API-Get.html#t:Get">Get</a> result)</td><tdclass="doc"><p>When implementing the handler for a <code><ahref="Servant-API-Get.html#t:Get">Get</a></code> endpoint,
just like for <code><ahref="Servant-API-Delete.html#t:Delete">Delete</a></code>, <code><ahref="Servant-API-Post.html#t:Post">Post</a></code>
and <code><ahref="Servant-API-Put.html#t:Put">Put</a></code>, the handler code runs in the
<code>EitherT (Int, String) IO</code> monad, where the <code><ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/Data-Int.html#t:Int">Int</a></code> represents
the status code and the <code><ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/Data-String.html#t:String">String</a></code> a message, returned in case of
failure. You can quite handily use <code><ahref="Control-Monad-Trans-EitherT.html#v:left">left</a></code>
to quickly fail if some conditions are not met.</p><p>If successfully returning a value, we just require that its type has
a <code><ahref="https://hackage.haskell.org/package/aeson-0.8.0.2/docs/Data-Aeson-Types.html#t:ToJSON">ToJSON</a></code> instance and servant takes care of encoding it for you,
yielding status code 200 along the way.</p></td></tr><tr><tdclass="src"><ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/Data-Typeable-Internal.html#t:Typeable">Typeable</a> (* -> *) <ahref="Servant-API-Get.html#t:Get">Get</a></td><tdclass="doc empty"> </td></tr><tr><tdclass="src"><spanclass="keyword">type</span><ahref="Servant-Server.html#t:Server">Server</a> (<ahref="Servant-API-Get.html#t:Get">Get</a> result) = <ahref="https://hackage.haskell.org/package/either-4.3.2/docs/Control-Monad-Trans-Either.html#t:EitherT">EitherT</a> (<ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/Data-Int.html#t:Int">Int</a>, <ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/Data-String.html#t:String">String</a>) <ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/System-IO.html#t:IO">IO</a> result</td><tdclass="doc empty"> </td></tr></table></div></div></div></div></div><divid="footer"><p>Produced by <ahref="http://www.haskell.org/haddock/">Haddock</a> version 2.15.0</p></div></body></html>