question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Masonite 4 will have a new routing engine as well as new routing syntax.

We will have a route syntax like this:

from masonite.routes import Route

Route.get('/url/1', 'Controller@show')
Route.post('/url/2', 'Controller@show')
Route.group(
    Route.get('/url/3', 'Controller@show')
    Route.post('/url/4', 'Controller@show')
)

The routing engine will be a simple Route class with a few helper methods on it. It will support all features of the current routing engine such as compilers, regex, @ style parameters (/users/@id) groups, deeper module controllers, global controllers, object based controllers, etc.

Currently every route is its own class (Get(), Post(), etc) and we have to loop through all of them to find a match. Now we will have a simple find('/request/path'). This abstracts a lot of the logic out and comes a single point of maintenance. Speed improvements, bug fixes, etc will be done there. This is a much simpler approach. Finding a route now becomes:

request.path #== /dashboard/1

Route.find(request.path) #== finds the route that matches the current path

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
girardinsamuelcommented, Jan 18, 2021

I guess a helper would be available too, to do it the other way around ? => from name to path, with url parameters if there are any

Route.reverse("auth.user", id=2)  #== /user/2
# or Route.reverse("auth.user", {"id": 2})  #== /user/2

in tests I often need to get url with params (both URL params such as the user id in previous example and GET parameters) so I end up in Django in doing

f"{reverse("auth.user", kwargs={"id": 2})}/?search=John"

and it bothers me to have to write this, so the reverse lookup could be able to handle required url params and additional get params, maybe like:

Route.reverse("auth.user", {"id": 2}, {"search": "John"})  #== /user/2?search=John
Route.reverse("auth.user", params={"id": 2}, query={"search": "John"})  #== /user/2?search=John
0reactions
josephmancusocommented, Nov 7, 2021

done in M4

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rewrites - next.config.js
When the rewrites function returns an array, rewrites are applied after checking the filesystem (pages and /public files) and before dynamic routes.
Read more >
IIS URL Rewriting and ASP.NET Routing - Microsoft Learn
The IIS URL Rewrite module can make rewriting decisions based on domain names, HTTP headers, and server variables. By default, ASP.NET routing ......
Read more >
Rewrite Requests | HAProxy Enterprise 2.6r1
Use the http-request configuration directives to rewrite HTTP requests. You can place it into a frontend , listen , or backend section. Use...
Read more >
Redirects and rewrites - Netlify Docs
Manage traffic to your site by defining redirect or rewrite rules in a _redirects file or a netlify.toml file.
Read more >
Angular - routing rewrite url - Stack Overflow
What about this: RouterModule.forRoot([ { path: 'page/:id', component: PageComponent }, { path: 'contact', component: ContactComponent } ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found