radiate-framework / framework

A WordPress plugin and theme framework
https://radiate-framework.github.io/
MIT License
4 stars 0 forks source link

Named routes #78

Closed BenRutlandWeb closed 3 years ago

BenRutlandWeb commented 3 years ago

Is your feature request related to a problem? Please describe. There's no easy way to reference API routes other than their URL which may not be simple to remember.

Describe the solution you'd like Named routes and the ability to get the URL with the name.

Route::get('posts/{id}/categories', CategoryController::class)->name('post.categories');

echo route('post.categories', ['id' => 1234]); // https://example.com/wp-json/api/posts/1234/categories

Describe alternatives you've considered Trying to remember API routes, and having to interpolate/concatenate URL parameters. hard-coding endpoints.

Additional context Routes are stored in the Router, it should be possible to assign names to each route, and then look these up from the router. There will also need to be a way to "build" a URL from the route and the given URL parameters.