2015-02-24 10:28:23 +01:00
|
|
|
{-# LANGUAGE DataKinds #-}
|
|
|
|
{-# LANGUAGE DeriveDataTypeable #-}
|
|
|
|
{-# LANGUAGE PolyKinds #-}
|
2015-05-02 03:21:03 +02:00
|
|
|
{-# OPTIONS_HADDOCK not-home #-}
|
2018-02-09 11:05:30 +01:00
|
|
|
module Servant.API.Capture (Capture, Capture', CaptureAll) where
|
2014-10-25 01:27:39 +02:00
|
|
|
|
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
|
|
|
--
|
2015-02-24 10:28:23 +01:00
|
|
|
-- >>> -- GET /books/:isbn
|
|
|
|
-- >>> type MyApi = "books" :> Capture "isbn" Text :> Get '[JSON] Book
|
2018-02-09 11:05:30 +01:00
|
|
|
type Capture = Capture' '[] -- todo
|
2015-02-24 10:28:23 +01:00
|
|
|
|
2018-02-09 11:05:30 +01:00
|
|
|
-- | '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
|
2018-01-17 12:19:14 +01:00
|
|
|
data CaptureAll (sym :: Symbol) (a :: *)
|
2016-05-26 17:49:04 +02:00
|
|
|
deriving (Typeable)
|
|
|
|
|
2015-02-24 10:28:23 +01:00
|
|
|
-- $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 }
|