oxhttp icon indicating copy to clipboard operation
oxhttp copied to clipboard

Add (optional) router to oxhttp

Open chrisglass opened this issue 3 years ago • 2 comments

The only thing preventing me from using this otherwise superb http server in more projects, is having some kind of router easily available/reusable.

Ideally, something that would also be capable of extracting URL parameters would be great.

If this is a desired feature, I'm happy to spend some time to implement it.

chrisglass avatar Aug 18 '22 13:08 chrisglass

The only thing preventing me from using this otherwise superb http server in more projects

Thank you for the very kind word. It's amazing to see other users of oxhttp. I built it because I wanted to have an HTTP library allowing to stream request and response bodies without having to rely a lot on an async I/O library.

is having some kind of router easily available/reusable. If this is a desired feature, I'm happy to spend some time to implement it.

That's a great question. I am more keen to keep this library as lightweight as possible. Inside of Oxigraph I just use a match statement and it served me well to implement a REST API. If you want to add stuff like argument extraction from the path based on URL patterns... maybe building an other crate would make sense (this crate might not even have to depend directly on oxhttp). This way you would be able to iterate without having to wait for code reviews and oxhttp users who don't care about it would not have to pull it in.

Ideally, something that would also be capable of extracting URL parameters would be great.

For query paramters, this is already built-in thanks to the Url crate. request.url().query_pairs() should do the job. For path, this is an other topic (c.f. supra).

Tpt avatar Aug 18 '22 13:08 Tpt