This repository is a work in progress, experimental exploration of strongly typed routing in Rust. It follows my previous work with Yesod in Haskell.
With strongly typed routes, you have a single enum
(or, in Haskell, ADT) that represents all potentially valid URLs in your web application. This type has parse and render functions, typically automatically generated by metaprogramming to avoid boilerplate errors. Entry to your application starts by calling that parse function to generate a value of this type. Instead of using string interpolation to generate links within your application, you use the render function.
There are a few advantages:
- If you change the structure of your routes, generated code automatically updates.
- More strongly, if you modify the parameters to your routes, existing code will fail to compile, and force you to update code appropriately.
- In my opinion, this is the single greatest strength of a strongly typed codebase: common mistakes are converted into compile time errors, and the compiler can tell you exactly what you need to fix.
- It can be far less tedious to generate URLs this way.
- There's one central data type you can reference to see all of the different parts of your application.
This is a work in progress, but for now it includes:
routetype
- Helper functions for parsing paths and query strings, properly supporting URL decoding and corner cases like "query string keys without values," e.g.
?foo&bar&baz
- A
Route
trait for strongly typed routes
- Helper functions for parsing paths and query strings, properly supporting URL decoding and corner cases like "query string keys without values," e.g.
routetype-derive
: A derive macro for theRoute
type. This is exported automatically fromroutetype
.routetype-warp
: A fewFilter
s for parsing and dispatching impls ofRoute
Possibly nothing. Possibly:
- Building out additional support for Warp
- Adding support for other frameworks like actix
- Adding a lower level Hyper-specific binding
- This likely would come with other helper functions to build out a microframework for simple apps
- Actually releasing what's already here to crates.io!
- Support multipath pieces, e.g. a trailing
Vec
ofString
s - Support embedding other routes within this route, which may simply rely on the multipath concept
If this is interesting, and you'd like to be a part, jump in! No guarantees on anything, but issues, PRs, and direct messages anywhere about your interest in the project are more likely to push me into turning this into something real.