-
Notifications
You must be signed in to change notification settings - Fork 48
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
Comments
@Covertness I plan to implement this next, after the Copper Pull Request is closed. |
It sounds good! Many HTTP libraries have it. |
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 |
@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! |
closed. please let me know if anyone want the similar feature. i will implement it. |
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
The text was updated successfully, but these errors were encountered: