Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL generation #24

Closed
aturon opened this issue Nov 8, 2018 · 3 comments
Closed

URL generation #24

aturon opened this issue Nov 8, 2018 · 3 comments
Assignees
Labels
design Open design question

Comments

@aturon
Copy link
Collaborator

aturon commented Nov 8, 2018

We need a story for generating URLs in code, given values for various parameters. One possibility would be to use named routes, like Actix does.

Let's discuss possible designs here, before implementing.

@aturon aturon added the design Open design question label Nov 8, 2018
@Keats
Copy link

Keats commented Nov 8, 2018

Copying my comment from internals:

Let’s say you have the following routes:

order-details: /orders/{id}
checkout: /checkout

and imagine you want to redirect the user after a POST on the checkout route to its order page with the newly created order ID. In Django you would redirect to the URL given by reverse("order-details", kwargs={'id': order.id}).

This requires 2 things (well 3, I’ll expand on the last one a bit later):

  • named routes: if I change a URL, I only want to change it at one place, not everywhere
  • named parameters: we could potentially skip that but it avoids tons of bugs and improve readability so that would be sad to not have them

The last point that would be nice, providing we have named routes is namespaces. It has been mentioned before as subrouters providing some routes.

If I do router.mount("/auth", "auth", &auth_urls) with the parameters being (prefix, namespace, router), I should be able to redirect to /auth/login by doing reverse("auth:login") for example if we follow the Django example and there is a view named login in the auth subrouter.

The Django docs for that bit are in https://docs.djangoproject.com/en/2.1/ref/urlresolvers/#reverse
I have used various frameworks in different languages but haven't seen much better than that. I believe Rails is very similar but don't quote me on that.

@bIgBV
Copy link
Contributor

bIgBV commented Feb 22, 2019

These are just some thoughts mentioned during the issue triage:

  • The primary issue is providing a way to leverage the compiler to generate URLs, instead of a stringly typed scheme
  • One such approach could be to use the endpoint itself as a key to generate the URL, something along the lines of router.get_url(&endpoint_fn)
  • This would piggyback on the way the modules are set up in the user's application

For now, me and @aturon will be doing a survey of the larger web ecosystem to see how this problem is solved and then outline a general approach for tide.

@yoshuawuyts
Copy link
Member

Note from triage: we're not sure this necessarily matches well with Rust. We're not sure how to proceed with this and how useful this is, so making a decision to close this for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Open design question
Projects
None yet
Development

No branches or pull requests

4 participants