handle fetching from external backend
Unanswered
Bosnian Coarse-haired Hound posted this in #help-forum
Bosnian Coarse-haired HoundOP
Hey all, i'm curently working on a nextjs project with another developer.
Our API doesn't live in the nextjs app, or in the same repo even, and we currently just write fetch calls to it.
The problem is that we don't have a centralized way of handling common logic, like checking for access token, and we end up copy-pasting a lot of logic.
How do you handle and scale up requests in a nextjs project? should we use a library? should we write some kind of centralized API function?
Our API doesn't live in the nextjs app, or in the same repo even, and we currently just write fetch calls to it.
The problem is that we don't have a centralized way of handling common logic, like checking for access token, and we end up copy-pasting a lot of logic.
How do you handle and scale up requests in a nextjs project? should we use a library? should we write some kind of centralized API function?
1 Reply
@Bosnian Coarse-haired Hound Hey all, i'm curently working on a nextjs project with another developer.
Our API doesn't live in the nextjs app, or in the same repo even, and we currently just write fetch calls to it.
The problem is that we don't have a centralized way of handling common logic, like checking for access token, and we end up copy-pasting a lot of logic.
How do you handle and scale up requests in a nextjs project? should we use a library? should we write some kind of centralized API function?
The validation and everything must be performed at the backend and with all the checks. For easier fetch calls, you can use openapi + [openapi-fetch](https://openapi-ts.dev/openapi-fetch/), this will help you guys share types infer the errors and responses