-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpClient.lean
More file actions
33 lines (27 loc) · 815 Bytes
/
HttpClient.lean
File metadata and controls
33 lines (27 loc) · 815 Bytes
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
import HttpClient.Basic
namespace HttpClient
def runRequest (request : Request) : IO (Http.Response String) := do
let connection ← Internal.connect request.uri
try
Internal.runRequest connection request
finally
connection.close
def http (method : Method) (url : String) (body : Option ByteArray)
: IO (Http.Response String) := do
let uri ← match parseUrl url with
| .ok res => pure res
| .error err => throw (IO.userError err)
let request := {
method := method
uri := uri
body := body
: Request
}
runRequest request
def get (url : String) : IO String := do
let response ← http .GET url .none
pure (response.body)
def post (url : String) (body : ByteArray) : IO String := do
let response ← http .POST url body
pure (response.body)
end HttpClient