安全的默认值
默认验证 TLS 证书,各阶段超时为五秒,重定向由你决定是否开启。
原生同步 HTTP 客户端。从简单的 GET,到持久会话和流式响应,用清晰的 API 连接你的应用与网络。
HTTP/1.1 · HTTPS 证书验证 · 原生 JSON
import req
def main() raises:
var response = req.get("https://example.com")
response.raise_for_status()
print(response.status_code)
print(response.text())
import req
def main() raises:
var owner = req.Client(base_url="https://example.com/")
with owner.context() as client:
var response = client.get("/")
response.raise_for_status()
print(response.text())
import req
def main() raises:
with req.stream("GET", "https://example.com") as body:
body.raise_for_status()
while True:
var chunk = body.read_chunk(65536)
if not chunk:
break
print(len(chunk.value()))
小而清晰的 API,让请求、响应和资源管理各就其位。
默认验证 TLS 证书,各阶段超时为五秒,重定向由你决定是否开启。
复用连接,在一个客户端中管理请求头、认证和有作用域的 Cookie。
发送 JSON、表单或字节,读取文本、结构化 JSON 或原始响应内容。
按需分块读取响应体,增量解码 gzip 和 deflate。
git clone https://github.com/mojoto/req.mojo.git
cd req.mojo
pixi install
make build