/
Method.purs
70 lines (64 loc) · 1.34 KB
/
Method.purs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
module Peregrine.Http.Method where
import Prelude
import Data.Maybe (Maybe(..))
-- | An HTTP request method.
data Method
= Get
| Put
| Post
| Delete
| Options
| Head
| Trace
| Connect
| Patch
derive instance eqMethod :: Eq Method
instance showMethod :: Show Method where
show = case _ of
Get -> "GET"
Put -> "PUT"
Post -> "POST"
Delete -> "DELETE"
Options -> "OPTIONS"
Head -> "HEAD"
Trace -> "TRACE"
Connect -> "CONNECT"
Patch -> "PATCH"
fromString :: String -> Maybe Method
fromString = case _ of
"GET" -> Just Get
"PUT" -> Just Put
"POST" -> Just Post
"DELETE" -> Just Delete
"OPTIONS" -> Just Options
"HEAD" -> Just Head
"TRACE" -> Just Trace
"CONNECT" -> Just Connect
"PATCH" -> Just Patch
_ -> Nothing
-- | Returns whether an HTTP request with the indicated method always supports
-- | a payload.
-- |
-- | The following methods always support payloads:
-- | - `PUT`
-- | - `POST`
-- | - `DELETE`
-- | - `PATCH`
-- |
-- | The following methods do **not** always support payloads:
-- | - `GET`
-- | - `HEAD`
-- | - `CONNECT`
-- | - `TRACE`
-- | - `OPTIONS`
alwaysSupportsPayload :: Method -> Boolean
alwaysSupportsPayload = case _ of
Put -> true
Post -> true
Delete -> true
Patch -> true
Get -> false
Head -> false
Connect -> false
Trace -> false
Options -> false