next-drupal icon indicating copy to clipboard operation
next-drupal copied to clipboard

Idea: Create Next API pages to proxy/mimic next-drupal methods

Open theodorosploumis opened this issue 3 years ago • 3 comments

As far as I can understand, all the next-drupal methods are async and return Promises. This disallows using them inside React components unless you use useEffect or similar hooks.

Do you believe is is a good idea to create a proxy like API route to handle the async functions? I mean create this inside the next-drupal starter kit.

E.g. for method getResource() we could have an API route on /api/next-drupal/getResource asking for the same parameters with the original function (https://next-drupal.org/docs/reference/getresource).

What are your thoughts?

theodorosploumis avatar Oct 10 '22 07:10 theodorosploumis

I see what you mean. We're actually doing same for most of our sites: using a proxy API route for making getResource and getResourceCollection calls.

The reason we did not ship this in the package and rather leave it to the dev for implementation is we want the package to be unopinionated and not hardcode the routes.

Maybe we could cover this in a guide instead? The implementation is quite simple.

What do you think?

(Note: this might change in the upcoming release of Next.js which will allow component-level data fetching)

shadcn avatar Oct 10 '22 11:10 shadcn

...component-level data fetching

That's great. Do you have any link for this discussion?

theodorosploumis avatar Oct 10 '22 12:10 theodorosploumis