Decoupled Router

Categories

Component ID

2924919

Component name

Decoupled Router

Component type

module

Maintenance status

Development status

Component security advisory coverage

covered

Downloads

424

Component created

Component changed

Component body

Decoupled Router provides an endpoint that will help you resolve path aliases and redirects for entity related routes. This is specially useful for decoupled applications where the editor wants full control over the paths available in the consumer application (for instance a React app).

To get a better understanding of this module read Decoupled Drupal Hard Problems: Routing.


Decoupled Router is an endpoint that receives a front-end path and tries to resolve it to an entity. To do so it follows as many redirects and URL aliases as necessary. In the example of /recipes/four-hour-stewed-lamb it would follow the redirect down to /recipes/4-hour-lamb-stew and resolve that URL alias to node:1. The endpoint provides some interesting information about the route and the underlying entity.

Decoupled Router

In a previous post, we discussed how multiple requests degrade performance significantly. With that in mind, making an extra request to resolve the redirects and aliases seems less attractive. We can solve this problem using the Subrequests module. Like we discussed in detail, we can use response tokens to combine several requests in one.

Imagine that we want to resolve /bread and display the title and image. However, we don’t know if /bread will resolve into an article or a recipe. We could use Subrequests to resolve the path and the JSON API entity in a single request.

Using subrequests

In the request above, we provide the path we want to resolve. Then we get the following response.

Subresponses