4 releases
Uses new Rust 2024
new 0.1.3 | May 22, 2025 |
---|---|
0.1.2 | May 22, 2025 |
0.1.1 | May 22, 2025 |
0.1.0 | May 22, 2025 |
#1303 in Web programming
39 downloads per month
14KB
103 lines
NRF Cloud Lib
A Rust library for interacting with the NRF Cloud API.
Features
- Simple and intuitive API
- Async/await support with Tokio
- JSON serialization/deserialization with Serde
- Typed request and response handling
- Customizable base URL
Installation
Add this to your Cargo.toml
:
[dependencies]
nrfcloudlib = "0.1.0"
Usage
Basic GET Request
use nrfcloudlib::NRFCloudClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let token = "your_api_token_here";
let client = NRFCloudClient::new(token);
// Simple GET request
let response = client.get("/devices").await?;
println!("Response: {}", response);
Ok(())
}
GET Request with Query Parameters
use nrfcloudlib::NRFCloudClient;
use serde::Serialize;
#[derive(Serialize)]
struct QueryParams {
limit: u32,
offset: u32,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let token = "your_api_token_here";
let client = NRFCloudClient::new(token);
let params = QueryParams {
limit: 10,
offset: 0,
};
let response = client.get_with_params("/devices", ¶ms).await?;
println!("Response: {}", response);
Ok(())
}
GET Request with JSON Deserialization
use nrfcloudlib::NRFCloudClient;
use serde::Deserialize;
#[derive(Deserialize, Debug)]
struct Device {
id: String,
name: String,
// Add other fields as needed
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let token = "your_api_token_here";
let client = NRFCloudClient::new(token);
// GET request with JSON deserialization
let device: Device = client.get_json("/devices/device-id").await?;
println!("Device: {:?}", device);
Ok(())
}
License
This project is licensed under the MIT License - see the LICENSE file for details.
Dependencies
~7–19MB
~239K SLoC