Setting up the environment to build a decoupled site
Since Drupal 8, the CMS can natively expose its internal structures (entities and configurations) to third-party systems.
With minimal or no configuration, you can start building the frontend of a Drupal website without using Twig and instead choose one of the many available JavaScript frameworks (such as Next.js, Vue.js, or React).
Drupal core provides two modules that can be used to expose content and other data to the to external systems:
- RESTful Web Services
- JSON:API
Both modules have pros and cons, and you should choose the one most appropriate for your use case. Sometimes, to fulfill requirements for some complex websites, you may have to use both.
In the following sections, we’ll expose data first with RESTful Web Services and then with JSON:API module to feed some vanilla JavaScript code. The output will be a fully decoupled HTML page that renders the details of a trip.