Robust, ergonomic CoAP server in Rust

Build Status Coverage Status Crates.io MIT licensed

An asynchronous CoAP server with a modern and ergonomic API for larger scale applications, inspired by warp and actix. CoAP offers an excellent alternative to HTTP for resource constrained environments like IoT devices.

Example

```rust use coapserver::app::{CoapError, Request, Response}; use coapserver::{app, CoapServer, FatalServerError, UdpTransport};

[tokio::main]

async fn main() -> Result<(), FatalServerError> { let server = CoapServer::bind(UdpTransport::new("0.0.0.0:5683")).await?; server.serve( app::new().resource( app::resource("/hello").get(handlegethello)) ).await }

async fn handlegethello(request: Request) -> Result { let whom = request .unmatchedpath .first() .cloned() .unwraporelse(|| "world".tostring());

let mut response = request.new_response();
response.message.payload = format!("Hello, {whom}").into_bytes();
Ok(response)

} ```

To experiment, I recommend using the excellent coap-client command-line tool, as with:

$ coap-client -m get coap://localhost/hello Hello, world

See examples for more.

Features

This project aims to be a robust and complete CoAP server, and in particular a more convenient alternative to MQTT for Rust-based projects:

Desired but not implemented:

Related Projects