GithubHelp home page GithubHelp logo

coap-server-rs's Introduction

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.

  • Ergonomic: Fluent app-builder API makes it easy to compose rich applications, including those that use more advanced CoAP features.
  • Concurrent: High concurrency is supported by using a separate spawned task for each request, allowing long running requests to not interfere with shorter running ones at scale.
  • Feature-rich: Conveniently supports a wide range of CoAP server features including Observe, and Block-wise Transfer.
  • Flexible: Supports pluggable transport backends with goals of supporting alternative async runtimes like embassy.

Example

use coap_server::app::{CoapError, Request, Response};
use coap_server::{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(handle_get_hello))
    ).await
}

async fn handle_get_hello(request: Request<SocketAddr>) -> Result<Response, CoapError> {
    let whom = request
        .unmatched_path
        .first()
        .cloned()
        .unwrap_or_else(|| "world".to_string());

    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:

  • Correct and convenient Observe support (RFC 7641)
  • Block-wise transfer support (RFC 7959)
  • Resource discovery and filtering via /.well-known/core (RFC 6690)
  • Multicast UDP
  • Fully concurrent request handling (no head-of-line blocking or scaling surprises!)
  • Ping/Pong keep-alive messages

Desired but not implemented:

Related Projects

coap-server-rs's People

Contributors

arturkow2 avatar jasta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

coap-server-rs's Issues

libcoap-sys integration tests

Would be really nice to be able to run integration tests against the gold standard libcoap to ensure correctness and interoperability

Abstract Tokio backend

Tokio should not be required to use this project and in particular we want to target embassy and possibly even simpler runtimes that support no_std.

match path up to '?' query parameter

While trying to pass some query parameters via URI, I noticed that e.g. resource '/abc', doesn't match if the URI contains query part '?.....'. So, the '/abc?a=1' is not matched at '/abc'.

Glancing over standard didn't provide me with definite answer, if this should be supported or not so I checked libcoap source, and there in coap uri parsing source (lines 233-260) they do split path into uri-path and uri-query parts.

Can this be implemented?

Initial implementation status

Tracking issue for the first big round of features that are needed for this project to be useful to others. Incomplete items in this list block crates.io submission

Features:

  • Working Observe support
  • Block-wise transfer
  • Multicast UDP
  • TCP transport (mostly as a proof of concept to show abstractions are correct)
  • /.well-known/core query filtering

Maturity:

  • rustdoc all the things

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.