servant/servant/src/Servant/API/Capture.hs

41 lines
1.2 KiB
Haskell
Raw Normal View History

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE PolyKinds #-}
2015-05-02 03:21:03 +02:00
{-# OPTIONS_HADDOCK not-home #-}
module Servant.API.Capture (Capture, Capture', CaptureAll) where
2018-03-11 16:58:31 +01:00
import Data.Typeable
(Typeable)
import GHC.TypeLits
(Symbol)
2014-11-22 15:55:50 +01:00
-- | Capture a value from the request path under a certain type @a@.
--
-- Example:
2015-06-03 13:13:49 +02:00
--
-- >>> -- GET /books/:isbn
-- >>> type MyApi = "books" :> Capture "isbn" Text :> Get '[JSON] Book
type Capture = Capture' '[] -- todo
-- | 'Capture' which can be modified. For example with 'Description'.
data Capture' (mods :: [*]) (sym :: Symbol) (a :: *)
deriving (Typeable)
2016-05-26 17:49:04 +02:00
-- | Capture all remaining values from the request path under a certain type
-- @a@.
--
-- Example:
--
-- >>> -- GET /src/*
-- >>> type MyAPI = "src" :> CaptureAll "segments" Text :> Get '[JSON] SourceFile
data CaptureAll (sym :: Symbol) (a :: *)
2016-05-26 17:49:04 +02:00
deriving (Typeable)
-- $setup
-- >>> import Servant.API
-- >>> import Data.Aeson
-- >>> import Data.Text
-- >>> data Book
-- >>> instance ToJSON Book where { toJSON = undefined }
2016-05-26 17:49:04 +02:00
-- >>> data SourceFile
-- >>> instance ToJSON SourceFile where { toJSON = undefined }