1{-# LANGUAGE TypeFamilies #-}
2{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE ScopedTypeVariables #-}
4{-# LANGUAGE DeriveDataTypeable #-}
5module Servant.API.Put where
7import Control.Monad.Trans.Either
10import Data.String.Conversions
12import Network.HTTP.Types
17import Servant.Utils.Client
19-- | Endpoint for PUT requests.
23instance ToJSON a => HasServer (Put a) where
24 type Server (Put a) = EitherT (Int, String) IO a
26 route Proxy action request respond
27 | null (pathInfo request) && requestMethod request == methodPut = do
28 e <- runEitherT action
29 respond . succeedWith $ case e of
31 responseLBS ok200 [("Content-Type", "application/json")] (encode out)
32 Left (status, message) ->
33 responseLBS (mkStatus status (cs message)) [] (cs message)
34 | null (pathInfo request) && requestMethod request /= methodPut =
35 respond $ failWith WrongMethod
37 | otherwise = respond $ failWith NotFound
39instance FromJSON a => HasClient (Put a) where
40 type Client (Put a) = BaseUrl -> EitherT String IO a
42 clientWithRoute Proxy req host =
43 performRequest methodPut req 200 host
45instance ToSample a => HasDocs (Put a) where
46 docsFor Proxy (endpoint, action) =
47 single endpoint' action'
49 where endpoint' = endpoint & method .~ DocPUT
51 action' = action & response.respBody .~ toSample p
52 & response.respStatus .~ 200
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