forked from citizennet/purescript-httpure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMethod.purs
47 lines (42 loc) · 964 Bytes
/
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
module HTTPure.Method
( Method(..)
, read
) where
import Prelude
import Node.HTTP (Request, requestMethod)
-- | These are the HTTP methods that HTTPure understands.
data Method
= Get
| Post
| Put
| Delete
| Head
| Connect
| Options
| Trace
| Patch
-- | If two `Methods` are the same constructor, they are equal.
derive instance eqMethod :: Eq Method
-- | Convert a constructor to a `String`.
instance showMethod :: Show Method where
show Get = "Get"
show Post = "Post"
show Put = "Put"
show Delete = "Delete"
show Head = "Head"
show Connect = "Connect"
show Options = "Options"
show Trace = "Trace"
show Patch = "Patch"
-- | Take an HTTP `Request` and extract the `Method` for that request.
read :: Request -> Method
read = requestMethod >>> case _ of
"POST" -> Post
"PUT" -> Put
"DELETE" -> Delete
"HEAD" -> Head
"CONNECT" -> Connect
"OPTIONS" -> Options
"TRACE" -> Trace
"PATCH" -> Patch
_ -> Get