coap_server/lib.rs
1//! Robust, ergonomic CoAP server in Rust.
2//!
3//! # Examples
4//! ```no_run
5//! use std::net::SocketAddr;
6//!
7//! use coap_server::app::{CoapError, Request, Response};
8//! use coap_server::{app, CoapServer, FatalServerError, UdpTransport};
9//!
10//! #[tokio::main]
11//! async fn main() -> Result<(), FatalServerError> {
12//! let server = CoapServer::bind(UdpTransport::new("0.0.0.0:5683")).await?;
13//! server.serve(
14//! app::new().resource(
15//! app::resource("/hello").get(handle_get_hello))
16//! ).await
17//! }
18//!
19//! async fn handle_get_hello(request: Request<SocketAddr>) -> Result<Response, CoapError> {
20//! let whom = request
21//! .unmatched_path
22//! .first()
23//! .cloned()
24//! .unwrap_or_else(|| "world".to_string());
25//!
26//! let mut response = request.new_response();
27//! response.message.payload = format!("Hello, {whom}").into_bytes();
28//! Ok(response)
29//! }
30//! ```
31//!
32//! See other [examples](https://github.com/jasta/coap-server-rs/tree/main/examples) for more information.
33
34extern crate core;
35
36pub use server::CoapServer;
37pub use server::FatalServerError;
38pub use udp::UdpTransport;
39
40pub mod app;
41pub mod packet_handler;
42pub mod server;
43pub mod transport;
44pub mod udp;