Skip to content

Trailing slash #205

@secretfader

Description

@secretfader

When creating REST APIs with Tide, I expect code like the following will be fairly common:

let mut router = App::new();
router.at("/resource").nest(|router| {
  router.at("/").get(async move |_| "Slash");
  router.at("").get(async move |_| "Blank");
});

I don't think developers will type both routes often, but in the wild, it's highly likely that we'll find both techniques in use. Being a bit more explicit about how routes are added the looked up may be an option to prevent confusion going forward. When looking at the example, it isn't entirely clear how an incoming request would be handled.

As of this writing, Tide renders two different responses: "Slash" appears at the path with a trailing slash (/resources/), and "Blank" at /resources. Which leads to the following questions:

  • Should Tide allow both a blank and slashed path in cases where the two are extremely similar?
  • Does Tide require a configuration option to differentiate between matching paths with trailing slashes and empty paths? Do we enable this option by default?

I'm sure there are other considerations I haven't accounted for yet, and aware that this change could affect future work in route-recognizer. The above is merely a starting point for this discussion, and I'd like to hear what others think.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions