servant-options: Provide responses to OPTIONS requests for Servant applications.

[ library, mit, web ] [ Propose Tags ]
Dependencies base (>=4.7 && <5), bytestring, http‑types, servant‑foreign, servant‑server, text, wai [details]
License MIT
Copyright 2017 Lyndon Maydwell
Author Lyndon Maydwell
Category Web
Home page
Uploaded by LyndonMaydwell at Tue Apr 4 04:05:39 UTC 2017
Distributions Fedora:, NixOS:
Downloads 294 total (9 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-04-04 [all 1 reports]
Hackage Matrix CI

Provide responses to OPTIONS requests for Servant applications.

[Skip to Readme]




Maintainer's Corner

For package maintainers and hackage trustees

Readme for servant-options-

[back to package description]


This library provides a middleware that returns HTTP OPTIONS responses for valid application routes defined by your (Proxy :: Proxy api). It is especially useful when trying to write an API that can be used in a cross-origin capacity, as browsers will send "pre-flight" checks by requesting OPTIONS for routes that are about to be called.




module MyApp where

import App
import Servant
import Network.Wai.Middleware.Cors
import Network.Wai.Middleware.Servant.Options

app :: Application
app = logStdoutDev
    $ cors (const $ Just policy)
    $ provideOptions apiProxy
    $ serve apiProxy apiServer
  policy = simpleCorsResourcePolicy
           { corsRequestHeaders = [ "content-type" ] }

See Also