DEV Community

Darcy
Darcy

Posted on

How to make a Drupal REST API

I want to create a React component on a Drupal8 site to display tweets.

To do so, I've decided to use Drupal as a backend to make a REST API of Twitter feed and use that feed in the React component.

Although I have written a couple REST APIs on NodeJS, I am confused about how/where to start on making a REST API on Drupal. Does anyone know a good tutorial/guide to get me started?

Much appreciated!

Top comments (1)

Collapse
 
giorgosk profile image
Giorgos Kontopoulos πŸ‘€

Perhaps a little late to this question but neverthless

Drupal includes in modules REST and JSONAPI in core modules to be used for rest api services. JSONAPI is the newest addition and probably a little more versatile but might luck documentation.

Here is an outdated comparison (JSONAPI is in core by now) drupal.org/docs/core-modules-and-t..., on the same guide (right side column) you will find more info about how to use JSONAPI.

If something is a drupal entity (perhaps you create the tweets as drupal entities) you most probably can expose them as API endpoints using either one of the above modules with just configuration (no custom coding).

If you want something more involved or custom you will probably need to create a custom REST api endpoint as seen here drupal.org/docs/8/api/restful-web-...

JSONAPI is probably not fit for custom endpoints as it is explained here drupal.org/project/jsonapi/issues/...