1{-# LANGUAGE TypeFamilies #-}
2{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE ScopedTypeVariables #-}
4module Servant.API.Delete where
7import Control.Monad.IO.Class
8import Control.Monad.Trans.Either
10import Data.String.Conversions
11import Network.HTTP.Types
18import qualified Network.HTTP.Client as Client
20-- | Endpoint for DELETE requests.
23instance HasServer Delete where
24 type Server Delete = EitherT (Int, String) IO ()
26 route Proxy action request respond
27 | null (pathInfo request) && requestMethod request == methodDelete = do
28 e <- runEitherT action
29 respond $ succeedWith $ case e of
31 responseLBS status204 [] ""
32 Left (status, message) ->
33 responseLBS (mkStatus status (cs message)) [] (cs message)
34 | null (pathInfo request) && requestMethod request /= methodDelete =
35 respond $ failWith WrongMethod
36 | otherwise = respond $ failWith NotFound
38instance HasClient Delete where
39 type Client Delete = URI -> EitherT String IO ()
41 clientWithRoute Proxy req uri = do
42 partialRequest <- liftIO $ reqToRequest req uri
44 let request = partialRequest { Client.method = methodDelete
47 innerResponse <- liftIO . __withGlobalManager $ \ manager ->
48 Client.httpLbs request manager
50 when (Client.responseStatus innerResponse /= status204) $
51 left ("HTTP DELETE request failed with status: " ++ show (Client.responseStatus innerResponse))
53instance HasDocs Delete where
54 docsFor Proxy (endpoint, action) =
55 single endpoint' action'
57 where endpoint' = endpoint & method .~ DocDELETE
59 action' = action & response.respBody .~ Nothing
60 & response.respStatus .~ 204
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