How do I fetch and store another endpoint in Strapi?

Viewed 142

I want to create an API in the Strapi. When this API hits, it will fetch data from another API service and store the strap as well. Later when I use this Strapi API I will use the previously retrieved data.

I found a documentation about external data, but the example here is hard to fully understand https://docs.strapi.io/developer-docs/latest/guides/external-data.html

1 Answers

This is how you can do that in a Strapi.

Create a new model to store external API then add a new controller with those steps:

  1. Check if requested data is present in database (using an unique ID or any way to identify the data for example)
  2. If data exists, return it
  3. If not, use 'axios' (installed with Strapi) or 'request' to fetch the external API
  4. Store the fetched data
  5. Return the fetched data
Related