Robust, ergonomic Rust CoAP server

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.

Status

GitHub tag Build Status MIT licensed

This project is a work in progress, attempting to provide a rich and stable codebase for further development. See Project Status tracking issue for more info.

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

Related Projects