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

[ library, mit, web ] [ Propose Tags ]

Provide responses to OPTIONS requests for Servant applications.


[Skip to Readme]

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0
Dependencies base (>=4.7 && <5), bytestring, http-types, servant-foreign, servant-server, text, wai [details]
License MIT
Copyright 2017 Lyndon Maydwell
Author Lyndon Maydwell
Maintainer maydwell@gmail.com
Category Web
Home page https://github.com/sordina/servant-options
Uploaded by LyndonMaydwell at 2017-04-04T04:05:39Z
Distributions Fedora:0.1.0.0, NixOS:0.1.0.0
Reverse Dependencies 2 direct, 0 indirect [details]
Downloads 3045 total (28 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-04-04 [all 1 reports]

Readme for servant-options-0.1.0.0

[back to package description]

Servant-Options

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.

Before:

After:

Usage:

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
  where
  policy = simpleCorsResourcePolicy
           { corsRequestHeaders = [ "content-type" ] }

See Also