feat: full http client implementation with reqwest like API interface#27
Merged
feat: full http client implementation with reqwest like API interface#27
reqwest like API interface#27Conversation
Joinhack
reviewed
Jul 8, 2025
Joinhack
approved these changes
Jul 8, 2025
…and error handling
…k FFI and enhancing error handling with RPC error types.
…version retrieval, file upload, and repository statistics
There was a problem hiding this comment.
Pull Request Overview
This PR replaces the legacy HTTP bindings with a full reqwest-like HTTP client built on the new JSON-RPC host call and also introduces a unified RpcClient. Key changes include:
- Added
RpcClientfor JSON-RPC 2.0 calls insrc/rpc.rs - Replaced
BlocklessHttpFFI withHttpClient,HttpOptions, andRequestBuilderinsrc/http.rs - Updated examples and README to use the new client and added the
base64dependency
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/rpc.rs | Added unified JSON-RPC client (RpcClient) with error mapping and tests |
| src/http.rs | Implemented HttpClient, HttpOptions, and RequestBuilder for HTTP RPC |
| src/lib.rs | Exposed http and rpc modules publicly |
| README.md | Updated build commands and example references |
| Cargo.toml | Added base64 dependency |
| examples/http_client.rs | New HTTP v2 client demo |
| examples/ipfs_api.rs | New IPFS API example demonstrating file uploads |
| examples/rpc.rs | New RPC client usage example |
| examples/httpbin.rs | Removed outdated HTTP example |
| examples/coingecko_oracle.rs | Updated to use the new HttpClient |
Comments suppressed due to low confidence (4)
src/http.rs:79
- [nitpick] The naming for binary body methods is inconsistent:
HttpOptionsprovidesbody_binarybutRequestBuilderusesbody_bytes. Consider unifying the method names to improve consistency, e.g., usebody_bytesin both places or rename both tobody_binary.
pub fn body_binary(mut self, data: Vec<u8>) -> Self {
src/http.rs:357
- [nitpick] Creating a new
RpcClientfor each HTTP request can lead to repeated buffer allocations and reset of thenext_idcounter. Consider reusing a singleRpcClientinstance insideHttpClientto reduce allocation overhead and preserve request sequencing.
fn execute(&self, builder: &RequestBuilder) -> Result<HttpResponse, HttpError> {
src/rpc.rs:146
- There are no tests covering the error mapping in
RpcClient::callwhenrpc_callreturns non-zero codes. Consider adding unit tests to simulate each return value and verify it maps to the correctRpcErrorvariant.
if result != 0 {
src/rpc.rs:90
- [nitpick] The public
RpcClientAPI lacks Rustdoc comments. Adding documentation forRpcClientand its key methods (new,call,ping,echo,version) would improve usability and maintainability.
pub struct RpcClient {
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request introduces significant updates to the Blockless SDK, focusing on improving HTTP client functionality, updating examples, and enhancing documentation.
Additionally introduced json-rpc based host-call; through which the HTTP-v2 client operates.
Going forward this will be the single/primary entrypoint/host-call through which all the modules call host functionality.
HTTP Client Enhancements:
HttpClient) with support for advanced features such as query parameters, authentication, multipart file uploads, and custom headers. This replaces the legacyBlocklessHttpimplementation. (examples/http_client.rs, examples/http_client.rsR1-R175)Example Updates:
examples/coingecko_oracle.rsto use the newHttpClientfor making HTTP requests, simplifying the code and improving readability. (examples/coingecko_oracle.rs, [1] [2]examples/ipfs_api.rsdemonstrating the use of the HTTP client for interacting with the IPFS API, including file uploads and repository statistics. (examples/ipfs_api.rs, examples/ipfs_api.rsR1-R298)examples/httpbin.rsand replaced it withexamples/http_client.rs, showcasing the new HTTP client capabilities. (examples/httpbin.rs, examples/httpbin.rsL1-L26)Documentation Updates:
README.mdto reflect changes in build commands, example file names, and descriptions of updated features. (README.md, [1] [2] [3]Dependency Updates:
base64crate as a new dependency to support encoding and decoding operations. (Cargo.toml, Cargo.tomlR13)Pre-requisites