norgbackup/norg/utils/httprequest.nim

21 lines
462 B
Nim
Raw Normal View History

2024-08-18 16:12:44 +02:00
import httpclient
export httpclient
proc sendHttpRequest*(meth: HttpMethod, url: string, body: string = "", headers: HttpHeaders = newHttpHeaders(), timeout: int = 10): Response =
let client = newHttpClient(headers = headers, timeout = timeout * 1000)
var res: Response
try:
case meth
of HttpGET:
res = client.get(url)
of HttpPost:
res = client.post(url, body)
else:
discard
finally:
client.close()
return res