I am currently writing a custom module - block plugin for Drupal 8 -
How do i go about consuming/sending external API data and displaying them using blocks?

Is this the standard way - consume/send external API data via plugin directly or through a controller and output it to a twig template? If so, how do i send data from controller to a custom plugin block?

Any suggestion is welcome. Thank you.

1 Answer 1


I'd do it this way:

  • Create a custom module
  • Create a class inside the src folder that consumes the API
  • Create a custom block inside your module: call the class there

Mostly it is better to fetch f.e. each hour and save the api data to custom entities. In this way you can cache the content in the block which enhances performance.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.