
Nanofish
A lightweight, no_std HTTP client for embedded systems built on top of Embassy networking with true zero-copy response handling.
Nanofish provides a simple HTTP client implementation that works on constrained environments with no heap allocation, making it suitable for microcontrollers and other embedded systems. It features zero-copy response handling where all response data is borrowed directly from user-provided buffers, ensuring maximum memory efficiency.
Key Features
- True Zero-Copy Response Handling - Response data is borrowed directly from user-provided buffers with no copying
- User-Controlled Memory Management - You provide the buffer, controlling exactly how much memory is used
- Full
no_stdcompatibility with no heap allocations - Built on Embassy for async networking
- Support for all standard HTTP methods (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS, TRACE, CONNECT)
- Intelligent response body handling (automatic text/binary detection based on Content-Type)
- Convenient header creation with pre-defined constants and methods
- Automatic handling of common headers
- DNS resolution
- Timeout handling and retries
- Optional TLS/HTTPS support (disabled by default)
Zero-Copy Architecture
Unlike traditional HTTP clients that copy response data multiple times, Nanofish uses a zero-copy approach:
- You control the buffer size - Provide a buffer as large or small as needed for your use case
- Direct memory references - Response body contains direct references to data in your buffer
- No hidden allocations - All memory usage is explicit and controlled by you
- Optimal for embedded - Perfect for memory-constrained environments
Feature Flags
tls: Enables TLS/HTTPS support viaembedded-tls. When disabled (default), only HTTP requests are supported and HTTPS requests will return an error.
To use nanofish with HTTP only (default):
[]
= "0.5.0"
To use nanofish with TLS/HTTPS support:
[]
= { = "0.5.0", = ["tls"] }
Example
use ;
use Stack;
async
Zero-Copy Benefits
// Traditional approach (copies data):
// 1. Read from network β internal buffer (copy #1)
// 2. Parse response β response struct (copy #2)
// 3. User gets β copied data (copy #3)
// Nanofish zero-copy approach:
// 1. Read from network β YOUR buffer (direct)
// 2. Parse response β references to YOUR buffer (zero-copy)
// 3. User gets β direct references to YOUR buffer (zero-copy)
let mut small_buffer = ; // For small responses
let mut large_buffer = ; // For large responses
// Same API, different memory usage - YOU decide!
let = client.get.await?;
let = client.get.await?;
Header Convenience Features
Nanofish provides convenient ways to work with common HTTP headers:
Pre-defined Header Constants
use headers;
// Common header names
let content_type = CONTENT_TYPE; // "Content-Type"
let authorization = AUTHORIZATION; // "Authorization"
let user_agent = USER_AGENT; // "User-Agent"
let accept = ACCEPT; // "Accept"
Pre-defined MIME Types
use mime_types;
// Common MIME types
let json = JSON; // "application/json"
let xml = XML; // "application/xml"
let text = TEXT; // "text/plain"
let html = HTML; // "text/html"
Convenience Methods
// Easy creation of common headers
let headers = ;
Response Handling
Nanofish automatically determines the appropriate response body type based on the Content-Type header:
// The response body is automatically parsed based on content type
match &response.body
// Convenience methods for response analysis
if response.is_success
if response.is_client_error
if response.is_server_error
// Easy access to common headers
if let Some = response.content_length
Convenience Methods
Nanofish provides convenience methods for all standard HTTP verbs, all using the same zero-copy approach:
// All methods require a buffer and return (HttpResponse, bytes_read)
let mut buffer = ;
// GET request
let = client.get.await?;
// POST request with JSON body
let json_body = br#"{"name": "John", "email": "john@example.com"}"#;
let post_headers = ;
let = client.post.await?;
// PUT request
let = client.put.await?;
// DELETE request
let = client.delete.await?;
// Other HTTP methods
let = client.patch.await?;
let = client.head.await?;
let = client.options.await?;
let = client.trace.await?;
let = client.connect.await?;
All methods return a Result<(HttpResponse, usize), Error> where:
HttpResponsecontains zero-copy references to data in your bufferusizeis the number of bytes read into your buffer
Memory Efficiency Examples
// Scenario 1: Memory-constrained device (1KB buffer)
let mut tiny_buffer = ;
let = client.get.await?;
// Perfect for small API responses, status checks, etc.
// Scenario 2: Streaming large data (32KB buffer)
let mut large_buffer = ;
let = client.get.await?;
// Handle larger responses, file downloads, etc.
// Scenario 3: Reuse the same buffer for multiple requests
let mut shared_buffer = ;
for url in urls
License
The MIT License (MIT) Copyright Β© 2025 rttf.dev
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the βSoftwareβ), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED βAS ISβ, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.