foxhole/app/hyap.hy
SouthFox e82c1ab94e
All checks were successful
/ run-pytest (push) Successful in 47s
[fix] compatible with hy 1.0.0
2024-09-30 00:46:49 +08:00

25 lines
745 B
Hy

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