servant-server

A family of combinators for defining webservices APIs and serving them

http://haskell-servant.readthedocs.org/

Version on this page:0.16
LTS Haskell 22.14:0.20@rev:4
Stackage Nightly 2024-03-28:0.20@rev:4
Latest on Hackage:0.20@rev:4

See all snapshots servant-server appears in

servant-server

servant

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.

Changes

The latest version of this document is on GitHub. Changelog for servant package contains significant entries for all core packages.

0.16

  • Rename ServantError to ClientError, ServantErr to ServerError #1131
  • servant-server Reorder HTTP failure code priorities #1103
  • servant-server Re-organise internal modules #1139
  • Allow network-3.0 #1107

0.15

  • Streaming refactoring. #991 #1076 #1077

    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-conduit servant-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.

  • Drop support for GHC older than 8.0 #1008 #1009

  • servant NewlineFraming encodes newline after each element (i.e last) #1079 #1011

  • servant Add lookupResponseHeader :: ... => Headers headers r -> ResponseHeader h a #1064

  • servant-server Add MonadMask Handler #1068

  • servant Export GetHeaders' #1052

  • servant Add Bitraversable and other Bi- instances for :<|> #1032

  • servant Add PutCreated method type alias #1024

  • servant Add ToSourceIO (NonEmpty a) instance #988

0.14.1

  • 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
    

    (#966 #972)

  • 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
    

    (#959)

  • Added NoFraming streaming strategy (#959)

  • servant-server File serving in polymorphic monad. i.e. Generalised types of serveDirectoryFileServer etc functions in Servant.Utils.StaticFiles (#953)

  • servant-server ReqBody content type check is recoverable. This allows writing APIs like:

          ReqBody '[JSON] Int      :> Post '[PlainText] Int
    :<|>  ReqBody '[PlainText] Int :> Post '[PlainText] Int
    

    which is useful when handlers are subtly different, for example may do less work. (#937)

0.13.0.1

  • Support base-compat-0.10

0.13

  • Streaming endpoint support. (#836)
  • servant Add Servant.API.Modifiers (#873)

0.12

Breaking changes

  • Added hoistServer member to the HasServer class, which is HasServer specific enter. (#804)

0.11

Breaking changes

  • Changed HasServer instances for Header to throw 400 when parsing fails (#724)
  • Added headersD block to Delayed (#724)

Other changes

  • Add err418, err422 error codes (#739)

0.10

Breaking changes

  • Handler is now an abstract datatype. Migration hint: change throwE to throwError. (#641)

  • Changed HasServer instances for QueryParam and QueryParam to throw 400 when parsing fails (#649)

Other changes

  • Added paramsD block to Delayed

  • Add err422 Unprocessable Entity (#646)

  • 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)

0.7.1

0.7

  • 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).

0.5

  • Add Config machinery (https://github.com/haskell-servant/servant/pull/327). This is a breaking change, as the signatures of both route, serve and the typeclass HasServer now take an additional parameter.
  • Support for the HttpVersion, IsSecure, RemoteHost and Vault combinators
  • Drop EitherT in favor of ExceptT
  • Use http-api-data instead of Servant.Common.Text
  • Remove matrix params.
  • Remove RouteMismatch.
  • Redefined constructors of RouteResult.
  • Added Delayed and related functions (addMethodCheck, addAcceptCheck, addBodyCheck, runDelayed)
  • Added support for Basic Authentication
  • Add generalized authentication support via the AuthServerData type family and AuthHandler handler

0.4.1

  • Bump attoparsec upper bound to < 0.14
  • Bump wai-app-static upper bound to < 3.2
  • Bump either upper bound to < 4.5

0.4

0.2.4

0.2.3