This library lets you implement an HTTP server with handlers for each endpoint of a servant API, handling most of the boilerplate for you.
Getting started
We’ve written a tutorial guide that introduces the core types and features of servant. After this article, you should be able to write your first servant webservices, learning the rest from the haddocks’ examples.
:<|> "capture-lenient" :> Capture' '[Lenient] "foo" Int :> GET
which will make the capture always succeed. Handlers will be of the
type Either String CapturedType, where Left err represents
the possible parse failure.
servant-server use queryString to parse QueryParam, QueryParams and QueryFlag #1249#1262
Some APIs need query parameters rewriting, e.g. in order to support
for multiple casing (camel, snake, etc) or something to that effect.
This could be easily achieved by using WAI Middleware and modifying
request’s Query. But QueryParam, QueryParams and QueryFlag use
rawQueryString. By using queryString rather then rawQueryString
we can enable such rewritings.
servantservant-server Make packages build-type: Simple#1263
We used build-type: Custom, but it’s problematic e.g.
for cross-compiling. The benefit is small, as the doctests
can be run other ways too (though not so conveniently).
0.16.2
singleton-bool-0.1.5 (SBool is re-exported)
Add discreteBool :: Dec (a :~: b) (GHC-7.8+)
Add Show, Eq, OrdSBool b instances.
dependencies update
0.16.1
Use http-api-data-0.4.1 (a part of its API is re-exported)
#1181
0.16
Rename ServantError to ClientError, ServantErr to ServerError#1131
The streaming functionality (Servant.API.Stream) is refactored to use
servant’s own SourceIO type (see Servant.Types.SourceT documentation),
which replaces both StreamGenerator and ResultStream types.
New conversion type-classes are ToSourceIO and FromSourceIO
(replacing ToStreamGenerator and BuildFromStream).
There are instances for conduit, pipes and machines in new packages:
servant-conduitservant-pipes and
servant-machines
respectively.
Writing new framing strategies is simpler. Check existing strategies for examples.
This change shouldn’t affect you, if you don’t use streaming endpoints.
Merge in servant-generic (by Patrick Chilton)
into servant (Servant.API.Generic),
servant-client-code (Servant.Client.Generic)
and servant-server (Servant.Server.Generic).
servant-server Deprecate Servant.Utils.StaticUtils, use Servant.Server.StaticUtils.
0.14
Stream takes a status code argument
-Stream method framing ctype a
+Stream method status framing ctype a
ToStreamGenerator definition changed, so it’s possible to write an instance
for conduits.
-class ToStreamGenerator f a where
- toStreamGenerator :: f a -> StreamGenerator a
+class ToStreamGenerator a b | a -> b where
+ toStreamGenerator :: a -> StreamGenerator b
Deprecate serveDirectory and introduce serveDirectoryFileServer,
serveDirectoryWebApp, serveDirectoryWebAppLookup, serveDirectoryEmbedded
and serveDirectoryWith which offer 4 default options and a more flexible
one for serving static files.
(#658)
DelayedIO is an instance of MonadResource, allowing safe resource handling.
(#622
, #674
, #675)
The Router type has been changed. Static router tables should now
be properly shared between requests, drastically increasing the
number of situations where servers will be able to route requests
efficiently. Functions layout and layoutWithContext have been
added to visualize the router layout for debugging purposes. Test
cases for expected router layouts have been added.
If an endpoint is discovered to have a non-matching “accept header”,
this is now a recoverable rather than a fatal failure, allowing
different endpoints for the same route, but with different content
types to be specified modularly.
Export throwError from module Servant
Add Handler type synonym
0.6.1
If servers use the BasicAuth combinator and receive requests with missing or
invalid credentials, the resulting error responses (401 and 403) could be
overwritten by subsequent alternative routes. Now BasicAuth uses FailFatal
and the error responses can’t be overwritten anymore.
0.6
Query parameters that can’t be parsed result in a 400 (was 404).