A requests like HTTP client for Mojo, leveraging libcurl under the hood.
First, you'll need to configure your pixi.toml file to include my Mojo community Conda channel. Add "https://repo.prefix.dev/mojo-community" to the list of channels.
Run the following commands in your terminal:
pixi add floki && pixi installThis will add floki to your project's dependencies and install it along with its dependencies.
There's two ways to build floki from source: directly from the Git repository or by cloning the repository locally.
Run the following commands in your terminal:
pixi add -g "https://github.com/thatstoasty/floki.git" && pixi install# Clone the repository to your local machine
git clone https://github.com/thatstoasty/floki.git
# Add the package to your project from the local path
pixi add -s ./path/to/floki && pixi installYou'll also need to install the curl_wrapper library, which provides a thin wrapper around libcurl to avoid issues with variadic arguments. You can add it by running:
pixi add curl_wrapper -g "https://github.com/thatstoasty/mojo-curl.git" --subdirectory shim --branch mainNote: Mojo cannot currently support calling C functions with variadic arguments, and the libcurl client interface 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!
import floki
fn main() raises -> None:
var response = floki.get("https://example.com")
for pair in response.headers.items():
print(pair.key, ": ", pair.value)
print(response.body.as_string_slice())- Add an option for streaming responses instead of loading it all into memory.
- Cookie support.
- Cleanup cookie parsing code, it seems pretty slow.
- 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.
- Add support for passing Dict data to session methods. Just passing a dict literal is a little limiting. I've tried, but it gets very hairy trying to convert it to an emberjson JSON object.
- Add support for converting dictionaries to form-encoded data for POST requests.
Reminder, this is a hobby project! You're free to fork it and make changes as you see fit.