heph icon indicating copy to clipboard operation
heph copied to clipboard

HTTP router

Open Thomasdezeeuw opened this issue 2 years ago • 1 comments

To route HTTP request based on the method and URL to the correct Service (#491).

impl Route {
    fn route<S>(&mut self, method: Method, url: &str, service: S) {
        // ...
    }

    fn get<S>(&mut self, url: &str, service: S) {
        self.route(Method::Get, url, service)
    }
}

Two additional useful features:

  • Wildcards, e.g. /static_files/* would route any URL that starts with /static_files/ to a service.
  • URL parameters, e.g. /user/{handle} would extract handle from the URL.

Possible data structure: https://en.wikipedia.org/wiki/Trie.

Blocked on #491.

Thomasdezeeuw avatar Sep 19 '21 13:09 Thomasdezeeuw

Pr https://github.com/Thomasdezeeuw/heph/pull/507 added the route! macro, but I'm leaving this open for a dynamic implementation.

Thomasdezeeuw avatar Oct 03 '21 10:10 Thomasdezeeuw