Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide Routing tool #4

Closed
jamesmunns opened this issue Jun 18, 2016 · 5 comments
Closed

Provide Routing tool #4

jamesmunns opened this issue Jun 18, 2016 · 5 comments

Comments

@jamesmunns
Copy link
Collaborator

It would be nice to have a tool to handle request routing. One good example is Iron's router functionality. This prevents every user from having to reimplement this functionality.

See: https://github.com/iron/router

@jamesmunns
Copy link
Collaborator Author

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

@Covertness
Copy link
Owner

It sounds good! Many HTTP libraries have it.

@jamesmunns
Copy link
Collaborator Author

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

@gagath
Copy link
Contributor

gagath commented Jul 18, 2017

@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!

@Covertness
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants