forked from haskell-servant/haskell-servant.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
111 lines (95 loc) · 6.36 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Home - haskell-servant</title>
<link rel="stylesheet" type="text/css" href="./css/default.css" />
</head>
<body>
<div id="header">
<div id="logo">
<a href="./">servant</a>
</div>
<div id="navigation">
<a href="./">Home</a>
<a href="./blog.html">Blog</a>
<a href="./tutorial">Tutorial</a>
<a href="./tips.html">Tips and tricks</a>
<a href="./talks.html">Talks</a>
<a href="https://github.com/haskell-servant/servant">Github</a>
</div>
</div>
<div id="content">
<h1>Home</h1>
<h1 id="webservice-api-combinators">Webservice API combinators</h1>
<p><em>servant</em> is a set of libraries that makes building Haskell webservices a breeze. With only the thinnest sliver of boilerplate, you get a type-safe service that is capable of generating client-side code (Haskell or Javascript) and documentation for free. See for yourself.</p>
<h2 id="a-webservice-api-is-a-type">A webservice API is a type</h2>
<pre class="sourceCode haskell"><code class="sourceCode haskell"> <span class="co">-- GET /date</span>
<span class="kw">type</span> <span class="dt">MyAPI</span> <span class="fu">=</span> <span class="st">"date"</span> <span class="fu">:></span> <span class="dt">Get</span> <span class="ch">'[JSON] Date</span>
<span class="co">-- GET /time/:tz</span>
<span class="fu">:<|></span> <span class="st">"time"</span> <span class="fu">:></span> <span class="dt">Capture</span> <span class="st">"tz"</span> <span class="dt">Timezone</span> <span class="fu">:></span> <span class="dt">Get</span> <span class="ch">'[JSON] Time</span></code></pre>
<p>This represents an API with two endpoints, both of which accept only GET requests, and which return a (JSON representation of) a <code>Date</code> and <code>Time</code> object, respectively.</p>
<h2 id="that-can-be-served">… that can be served …</h2>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">server ::</span> <span class="dt">Server</span> <span class="dt">MyAPI</span>
server <span class="fu">=</span> getDate <span class="fu">:<|></span> getTimeForTZ
<span class="kw">where</span> getDate <span class="fu">=</span> liftIO getCurrentDate
getTimeForTZ tz <span class="fu">=</span> liftIO <span class="fu">$</span> getTimeAtTZ tz
<span class="co">-- assuming we have</span>
<span class="ot">getCurrentDate ::</span> <span class="dt">IO</span> <span class="dt">Date</span>
<span class="ot">getTimeAtTZ ::</span> <span class="dt">Timezone</span> <span class="ot">-></span> <span class="dt">IO</span> <span class="dt">Time</span>
<span class="ot">main ::</span> <span class="dt">IO</span> ()
main <span class="fu">=</span> run <span class="dv">8000</span> <span class="fu">$</span> serve myAPI server
<span class="kw">where</span><span class="ot"> myAPI ::</span> <span class="dt">Proxy</span> <span class="dt">MyAPI</span>
myAPI <span class="fu">=</span> <span class="dt">Proxy</span></code></pre>
<p>One handler per endpoint. The handlers’ types must match those described in the endpoint. URL captures, GET parameters, headers or request body must be explicitly mentioned and get automatically turned into arguments to the handlers.</p>
<h3 id="and-more">… and more!</h3>
<p>This representation lets us generate client-side querying functions automatically, in Haskell and Javascript. API docs too!</p>
<p>To find out more, please check our <a href="./tutorial">tutorial</a>.</p>
<h1 id="documentation-and-community">Documentation and community</h1>
<h2 id="tutorials">Tutorials</h2>
<ul>
<li><a href="./tutorial">Tutorial</a> (it’s recommended to start here)</li>
<li><a href="./extending.html">Extending servant</a></li>
<li><a href="./client-in-5-minutes.html">Hackage API client in 5 minutes</a></li>
<li><a href="https://halcyon.sh/tutorial/">Developing a servant application with Halcyon</a></li>
<li>See <a href="./talks.html">the talks</a></li>
</ul>
<h2 id="examples">Examples</h2>
<p><em>servant</em> comes with quite a few examples, among which the ones studied in the <a href="./tutorial">tutorial</a>. You can find them <a href="https://github.com/haskell-servant/servant/tree/master/servant-examples">here</a>.</p>
<h2 id="haddocks">Haddocks</h2>
<ul>
<li><a href="http://hackage.haskell.org/package/servant">servant</a>, API types and combinators</li>
<li><a href="http://hackage.haskell.org/package/servant-server">servant-server</a>, for creating a server</li>
<li><a href="http://hackage.haskell.org/package/servant-client">servant-client</a>, for generating haskell functions to query APIs automatically</li>
<li><a href="http://hackage.haskell.org/package/servant-jquery">servant-jquery</a>, for generating javascript functions to query APIs automatically</li>
<li><a href="http://hackage.haskell.org/package/servant-docs">servant-docs</a>, for assistance in API docs generation</li>
</ul>
<h2 id="mailing-list-and-irc">Mailing list and IRC</h2>
<ul>
<li><a href="https://groups.google.com/forum/#!forum/haskell-servant">Mailing list</a></li>
<li><strong>#servant</strong> on the freenode IRC network</li>
</ul>
<h2>Blog</h2>
<p>Latest blog posts (<a href="./blog.html">all</a>)</p>
<ul>
<li>
<a href="./posts/2015-05-25-servant-paper-wgp-2015.html">servant paper submitted to WGP 2015</a>,
by <i>Alp Mestanogullari</i>
- May 25, 2015
</li>
<li>
<a href="./posts/2015-05-10-servant-0.4-released.html">servant 0.4 released</a>,
by <i>The servant team</i>
- May 10, 2015
</li>
</ul>
</div>
<div id="footer">
Site proudly generated by
<a href="http://jaspervdj.be/hakyll">Hakyll</a>
-
<a href="https://github.com/haskell-servant/haskell-servant.github.io">Source</a>
</div>
</body>
</html>