-
Notifications
You must be signed in to change notification settings - Fork 6
feat: full http client implementation with reqwest like API interface
#27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 {
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