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.
```rust use coapserver::app::{CoapError, Request, Response}; use coapserver::{app, CoapServer, FatalServerError, UdpTransport};
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
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.
This project aims to be a robust and complete CoAP server, and in particular a more convenient alternative to MQTT for Rust-based projects:
/.well-known/core
(RFC 6690)Desired but not implemented:
/.well-known/core
filtering.