Provide responses to OPTIONS requests for Servant applications.

Latest on Hackage:

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow to host generated Haddocks.

MIT licensed by Lyndon Maydwell
Maintained by


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

comments powered byDisqus