Coder Social home page Coder Social logo

Provide Routing tool about coap-rs HOT 5 CLOSED

covertness avatar covertness commented on July 4, 2024
Provide Routing tool

from coap-rs.

Comments (5)

jamesmunns avatar jamesmunns commented on July 4, 2024 1

Started work. Follow along here:

Branch:

https://github.com/jamesmunns/coap-rs/tree/coap-router

Diff:

https://github.com/jamesmunns/coap-rs/compare/packet-refactor...jamesmunns:coap-router?expand=1

from coap-rs.

jamesmunns avatar jamesmunns commented on July 4, 2024

@Covertness I plan to implement this next, after the Copper Pull Request is closed.

from coap-rs.

Covertness avatar Covertness commented on July 4, 2024

It sounds good! Many HTTP libraries have it.

from coap-rs.

gagath avatar gagath commented on July 4, 2024

@jamesmunns Any news about your work? I am currently routing using the following structure:

fn request_handler(req: CoAPRequest) -> Option<CoAPResponse> {
    println!("Receive request: {:?}", req);

    let uri = get_uri(&req);

    if let Some(mut response) = req.response {

        // Default payload
        let mut code = Responses::NotFound;
        let mut resp = "not found".to_owned().into_bytes();

        match uri.as_ref() {
            "status" => {
                code = Responses::Content;
                resp = "available".to_owned().into_bytes();
            },
            "json_status" => {
                code = Responses::Content;
                resp = "{\"status\": \"available\"}".to_owned().into_bytes();
            },
            _ => {

            }
        }

        // Customize response payload
        response.message.header.code = MessageClass::ResponseType(code);
        response.message.payload = resp;

        // Return the modified response
        return Some(response);
    }

    // Return the auto-generated response
    req.response
}

But a router would be nice!

from coap-rs.

Covertness avatar Covertness commented on July 4, 2024

closed. please let me know if anyone want the similar feature. i will implement it.

from coap-rs.

Related Issues (20)

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.