How to handle Nextjs with external REST API

How do you guys handle using Next.js with external REST APIs? Is it okay to wrap all fetch calls within actions (in order to use revalidateTag)? How to handle jwt auth in that scenario?
2 Replies
Teapot
TeapotOP6mo ago
I’m looking for some sources of information, because so far I’ve only found information about situations where Next.js can directly communicate with a database.
Hackder
Hackder6mo ago
I am not really sure what exactly are you asking about. When you are integrating an external API, you generaly have an "API key" which you can use to make requests to such api from your backend. (So yes, you will have to have a server action or an endpoint, which will make the API call) If the API you are trying to use doesn't have a concept of an "API key", and you need to authenticate, it really depends on your situation. If you make these request often, you will need to store the JWT in the database, and revalidate it when necessary. I would try to avoid this tho. Make sure you can't use an API token, or if it's an external service that the user signs in, OAuth would make sense.
Want results from more Discord servers?
Add your server