The servant-options package

[Tags:library, mit]

Provide responses to OPTIONS requests for Servant applications.


[Skip to Readme]

Properties

Versions 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 Tue Apr 4 04:05:39 UTC 2017 by LyndonMaydwell
Distributions NixOS:0.1.0.0
Downloads 49 total (5 in the last 30 days)
Votes
0 []
Status Docs available [build log]
Last success reported on 2017-04-04 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Readme for servant-options

Readme for servant-options-0.1.0.0

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