1{-# LANGUAGE PolyKinds #-}
2{-# LANGUAGE TypeFamilies #-}
3{-# LANGUAGE TypeOperators #-}
4{-# LANGUAGE FlexibleInstances #-}
5{-# LANGUAGE ScopedTypeVariables #-}
6module Servant.API.GetParam where
9import Data.String.Conversions
12import Network.HTTP.Types
19-- * GET params support (i.e query string arguments)
22instance (KnownSymbol sym, FromText a, HasServer sublayout)
23 => HasServer (GetParam sym a :> sublayout) where
25 type Server (GetParam sym a :> sublayout) =
26 Maybe a -> Server sublayout
28 route Proxy subserver globalPathInfo request respond = do
29 let querytext = parseQueryText $ rawQueryString request
31 case lookup paramName querytext of
32 Nothing -> Nothing -- param absent from the query string
33 Just Nothing -> Nothing -- param present with no value -> Nothing
34 Just (Just v) -> fromText v -- if present, we try to convert to
37 route (Proxy :: Proxy sublayout) (subserver param) globalPathInfo request respond
39 where paramName = cs $ symbolVal (Proxy :: Proxy sym)
41instance (KnownSymbol sym, ToText a, HasClient sublayout)
42 => HasClient (GetParam sym a :> sublayout) where
44 type Client (GetParam sym a :> sublayout) =
45 Maybe a -> Client sublayout
47 -- if mparam = Nothing, we don't add it to the query string
48 clientWithRoute Proxy req mparam =
49 clientWithRoute (Proxy :: Proxy sublayout) $
50 appendToQueryString pname mparamText req
52 where pname = pack pname'
53 pname' = symbolVal (Proxy :: Proxy sym)
54 mparamText = fmap toText mparam
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list