servant-xml (empty) → 1.0.0
raw patch · 4 files changed
+116/−0 lines, 4 filesdep +basedep +bytestringdep +http-media
Dependencies added: base, bytestring, http-media, servant, xmlbf
Files
- LICENSE +30/−0
- README.md +8/−0
- servant-xml.cabal +36/−0
- src/Servant/XML.hs +42/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Author name here (c) 2018++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Author name here nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,8 @@+# servant-xml++Servant support for XML.++Types with a `ToXml` instance will be automatically marshalled into XML+and successfully returned by Servant endpoints.+In implementing `toXml`, you can use the `element` and `text` primatives+found in the *xmlbf* library.
+ servant-xml.cabal view
@@ -0,0 +1,36 @@+-- This file has been generated from package.yaml by hpack version 0.20.0.+--+-- see: https://github.com/sol/hpack+--+-- hash: 75be9f1914f9d92bff857fc253157776eb3d96b62a3fe6f8651a841647e01fbb++name: servant-xml+version: 1.0.0+synopsis: Servant support for the XML Content-Type+description: Servant support for the Content-Type of /application\/xml/. Anything with a 'Xmlbf.ToXml' instance can be automatically marshalled.+category: Web+homepage: https://github.com/fosskers/servant-xml+author: Colin Woodbury+maintainer: colingw@gmail.com+copyright: 2018 Colin Woodbury+license: BSD3+license-file: LICENSE+build-type: Simple+cabal-version: >= 1.10++extra-source-files:+ README.md++library+ hs-source-dirs:+ src+ ghc-options: -fwarn-unused-imports -fwarn-unused-binds -fwarn-name-shadowing -fwarn-unused-matches -fwarn-incomplete-patterns -fwarn-incomplete-uni-patterns+ build-depends:+ base >=4.7 && <5+ , bytestring+ , http-media >=0.7 && <0.8+ , servant >=0.11 && <0.13+ , xmlbf >=0.3 && <0.4+ exposed-modules:+ Servant.XML+ default-language: Haskell2010
+ src/Servant/XML.hs view
@@ -0,0 +1,42 @@+{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}+{-# LANGUAGE OverloadedStrings #-}++-- |+-- Module : Servant.XML+-- Copyright : (c) Colin Woodbury, 2018+-- License : BSD3+-- Maintainer: Colin Woodbury <colingw@gmail.com>+--+-- Servant support for XML.+--+-- Types with a `ToXml` instance will be automatically marshalled into XML+-- and successfully returned by Servant endpoints.+-- In implementing `toXml`, you can use the `element` and `text` primatives+-- found in the /xmlbf/ library.++module Servant.XML where++import Data.ByteString.Builder (toLazyByteString)+import qualified Network.HTTP.Media as M+import Servant.API+import Xmlbf++---++-- | The /application\/xml/ Content-Type. To be used in Servant endpoints like:+--+-- @+-- data Foo = ...+--+-- instance ToXml Foo where+-- toXml foo = ...+--+-- type API = ... :\<|\> "foo" :> Get '[XML] Foo+-- @+data XML++instance Accept XML where+ contentType _ = "application" M.// "xml" M./: ("charset", "utf-8")++instance ToXml a => MimeRender XML a where+ mimeRender _ = toLazyByteString . encode . toXml