foxhole/app/hyap.hy
SouthFox fee55145d9
All checks were successful
/ run-pytest (push) Successful in 2m29s
[refactor] rewrite post in hylang
2024-02-28 13:45:13 +08:00

25 lines
695 B
Hy

#!/usr/bin/env hy
(import httpx)
(import loguru [logger])
(import app [config])
(import app.httpsig [auth])
(defn/a fetch
[url]
(.info logger url)
(return (.json
(with/a [client (.AsyncClient httpx)]
(let [headers {"User-Agent" config.USER_AGENT
"Accept" config.AP_CONTENT_TYPE}]
(await (.get client url :headers headers)))))))
(defn/a post
[url payload]
(with/a [client (.AsyncClient httpx)]
(let [headers {"User-Agent" config.USER_AGENT
"Accept" config.AP_CONTENT_TYPE}]
(setv resp
(await (.post client url :headers headers :json payload :auth auth)))
(.raise_for_status resp)
(return resp))))