0 | module Network.HTTP.Method
 1 |
 2 | import Generics.Derive
 3 | import Derive.Prelude
 4 |
 5 | %hide Generics.Derive.Eq
 6 | %hide Generics.Derive.Ord
 7 | %hide Generics.Derive.Show
 8 |
 9 | %language ElabReflection
10 |
11 | public export
12 | data Method : Type where
13 |   GET : Method
14 |   HEAD : Method
15 |   POST : Method
16 |   PUT : Method
17 |   DELETE : Method
18 |   CONNECT : Method
19 |   OPTIONS : Method
20 |   PATCH : Method
21 |   Custom : String -> Method
22 |
23 | %runElab derive "Method" [Generic, Meta, Eq, DecEq, Ord, Show]
24 |
25 | export
26 | http_method_to_string : Method -> String
27 | http_method_to_string (Custom x) = toUpper x
28 | http_method_to_string x = show x
29 |
30 | export
31 | string_to_http_method : String -> Method
32 | string_to_http_method x =
33 |   case toUpper x of
34 |     "GET" => GET
35 |     "HEAD" => HEAD
36 |     "POST" => POST
37 |     "PUT" => PUT
38 |     "DELETE" => DELETE
39 |     "CONNECT" => CONNECT
40 |     "OPTIONS" => OPTIONS
41 |     "PATCH" => PATCH
42 |     x => Custom x
43 |
44 | export
45 | FromString Method where
46 |   fromString = string_to_http_method
47 |