| Crates.io | ic-http-types |
| lib.rs | ic-http-types |
| version | 0.1.0 |
| created_at | 2025-04-17 11:33:36.134912+00 |
| updated_at | 2025-04-17 11:33:36.134912+00 |
| description | HTTP request and response types for the Internet Computer |
| homepage | |
| repository | https://github.com/dfinity/ic |
| max_upload_size | |
| id | 1637536 |
| size | 40,516 |
ic-http-types is a Rust crate that provides types for representing HTTP requests and responses. These types are designed to simplify working with HTTP communication in canister development on the Internet Computer.
HttpRequest: A struct for encapsulating HTTP request details, including method, URL, headers, and body.HttpResponse: A struct for encapsulating HTTP response details, including status code, headers, and body.HttpResponseBuilder: A builder pattern for constructing HttpResponse objects.Add the crate to your Cargo.toml:
[dependencies]
ic-http-types = "0.1.0"
use ic_canisters_http_types::{HttpRequest, HttpResponseBuilder};
use serde_bytes::ByteBuf;
fn main() {
// Create an HTTP request
let request = HttpRequest {
method: "GET".to_string(),
url: "/path/to/resource?query=1".to_string(),
headers: vec![("Content-Type".to_string(), "application/json".to_string())],
body: ByteBuf::defaBult(),
};
// Extract the path from the request URL
println!("Path: {}", request.path());
// Build an HTTP response
let response = HttpResponseBuilder::ok()
.header("Content-Type", "application/json")
.body("{\"message\": \"success\"}")
.build();
println!("Response Status: {}", response.status_code);
}
For detailed documentation, visit the Rust Docs.
This project is licensed under the Apache License 2.0.
If you decide to contribute, we encourage you to announce it on the Forum!