Provide Routing tool
jamesmunns opened this issue · 5 comments
jamesmunns commented
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.
jamesmunns commented
@Covertness I plan to implement this next, after the Copper Pull Request is closed.
Covertness commented
It sounds good! Many HTTP libraries have it.
jamesmunns commented
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 commented
@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 commented
closed. please let me know if anyone want the similar feature. i will implement it.