A synchronous HTTP client for Mojo.
Language: English | 中文
Documentation: https://mojoto.github.io/req.mojo/
From a Pixi workspace already configured for Mojo, add the official Modular Community channel and install Req:
pixi workspace channel add --prepend https://repo.prefix.dev/modular-community
pixi add reqThe community recipe is being submitted for review; these commands become available once the package is published to the channel. Req uses Mojo 1.1.0. Pixi installs the matching compiler, libcurl, and zlib, together with Req's precompiled module, CPU JSON modules, and native shared library. Req loads the native transport from the active Pixi environment automatically; no C build or extra linker flags are needed.
Save the following example as main.mojo in your workspace root:
import req
def main() raises:
var response = req.get("https://example.com")
response.raise_for_status()
print(response.status_code)
print(response.headers["Content-Type"])
print(response.text())Run the example:
pixi run mojo main.mojoOr compile it and run the binary inside the Pixi environment:
pixi run mojo build main.mojo -o main
pixi run ./mainSee the getting started guide for more examples and package integration.
make install-hooks # Install the pre-commit formatter (once per clone)
make test # Run tests
make format # Format code
make build # Build the packageThe hook runs make format before each commit. If formatting changes files,
review and stage them, then commit again. It does not stage files automatically.
See the development guide for more commands and documentation setup.
Req is MIT licensed.