A requests like HTTP client for Mojo, leveraging libcurl under the hood.
- First, you'll need to configure your
pixi.tomlfile to include my Conda channel. Add"https://repo.prefix.dev/mojo-community"to the list of channels. - Next, add
flokito your project's dependencies by runningpixi add floki. - Add the helper library for libcurl bindings by running
pixi add curl_wrapper -g "https://github.com/thatstoasty/mojo-curl.git" --subdirectory shim --branch main.- Mojo cannot currently support calling C functions with variadic arguments, and libcurl makes heavy use of them. The
curl_wrapperlibrary provides a thin wrapper around libcurl to avoid this issue. Remember to always validate the code you're pulling from third-party sources!
- Mojo cannot currently support calling C functions with variadic arguments, and libcurl makes heavy use of them. The
- Finally, run
pixi installto install inflokiand its dependencies. You should see the.mojopkgfiles in$CONDA_PREFIX/lib/mojo/.
Please check out the test/test_session.mojo for an example of how to use the client for now. I will add documentation later.
from floki import Session
fn main() raises -> None:
var client = Session()
var response = client.get("https://example.com")
for pair in response.headers.items():
print(String(pair.key, ": ", pair.value))
print("Response body: ", response.body.as_string_slice())- Add an option for streaming responses instead of loading it all into memory.
- Cookie support.
- Sus out the myriad of bugs and edge cases that may arise as libcurl and requests can do A LOT of things, that I've never used before. Please open issues and open PRs to help address these gaps where possible.
- Add methods to free Session explicitly, same with Easy handles.
Reminder, this is a hobby project! You're free to fork it and make changes as you see fit.