Search code examples
drupalddev

How to build a REST API between two sites using DDEV?


I got two drupal sites running with DDEV.

First one is a Drupal 7 that populates data from database in several REST API endpoints.

The other one is a Drupal 9 that needs to consume the data from these endpoints.

I've found some posts like Communication between two ddev projects, but I can't get it working.

I'm quite noob with Docker & DDEV, so I will appreciate a step-by-step (or more accurate) guide about how configure both DDEV environments, so the Drupal 9 site can consume the REST API exposed by the Drupal 7 site.

The following are my DDEV config.yaml and ddev describe for both sites:

Drupal 7 site:

name: drupal7
type: drupal7
docroot: "www"
php_version: "5.6"
webserver_type: apache-fpm
router_http_port: "80"
router_https_port: "443"
xdebug_enabled: false
additional_hostnames: ['drupal7.local']
additional_fqdns: ['drupal7.local']
mariadb_version: "10.3"
mysql_version: ""
nfs_mount_enabled: true
mutagen_enabled: false
use_dns_when_possible: true
composer_version: "2"
web_environment: []

dev describe for drupal 7 site

Drupal 9 site:

name: drupal9
type: drupal9
docroot: web
php_version: "8.1"
webserver_type: apache-fpm
router_http_port: "80"
router_https_port: "443"
xdebug_enabled: false
additional_hostnames: ['drupal9.local']
additional_fqdns: ['drupal9.local']
database:
  type: mariadb
  version: "10.3"
nfs_mount_enabled: false
mutagen_enabled: false
use_dns_when_possible: true
composer_version: "2"
web_environment: []
nodejs_version: "16"

ddev describe for drupal 9 site

Additional info:

  • DDEV 1.21.1
  • Docker 20.10.17 (Docker Desktop 4.12.0)

Solution

  • Two projects can easily communicate with each other, as described in the FAQ

    Also see Communication between two ddev projects and Communicating between ddev projects via http/s

    I hope those links will get you started. The bottom line is you can use either the full name of the web container (like ddev-<projectname>-web or the FQDN of the target site (like https://someapi.ddev.site) (second one requires minor configuration).