Next.js Discord

Discord Forum

Frontend call external API with Axiox

Answered
melvin_vga posted this in #help-forum
Open in Discord
Hello, I set up a frontend with nextjs and I send axios requests to my laravel backend, but they never reach the backend even though I can call my backend without problem with postman
Answered by Anay-208
Explaination:
- The data for cached in the .next folder
- With fetch api, you can easily control the cache
- The issue was fixed by deleting the .next folder
View full answer

34 Replies

Bengal
Do you see any requests actually arrive on your backend? or not at all?
Is your backend actually reachable from your hosted environment, and if you're using fetch calls client-side, is it reachable from client PCs?
I can log in and register without problem but these are the only routes that work (cf service auth / event) actually i'm trying to get all on Event
postman :
Bengal
shouldn't baseUrl in the second image then be /api/event ?
your postman shows a get for /api/event
my axios service are like this :
my axios service are like this :
when I connect I have this message in the back with the service that I previously sent :
but when I try to call EventService.getAll() my backend is not submitted and no request appears in the logs
i call my backend i this action file :
my fear is that next only allows data fetch to have its own backend but I have seen people use it with nest or other backends
because I don't understand where the problem comes from with authentication that works but not the rest of my routes
thank you in advance for your help 🙏
@melvin_vga Click to see attachment
Sloth bear
Try console.log the response and see where it's actually going and the error code? That should give you some more clues
@Anay-208 I dont think think baseUrl should be there
I currently use Redaxios which is an equivalent of Ky, I preferred to keep the diminutive axios in the functions out of habit but I just saw that Ky was slightly lighter so I am considering switching
@Sloth bear Try console.log the response and see where it's actually going and the error code? That should give you some more clues
console.log(response) :
but not logs on my backend
can you try deleting .next folder and restarting the app?
ohh
this is working fine
i got my data
@Anay-208 can you try deleting `.next` folder and restarting the app?
Do you have a quick explanation for me?
@melvin_vga Do you have a quick explanation for me?
Explaination:
- The data for cached in the .next folder
- With fetch api, you can easily control the cache
- The issue was fixed by deleting the .next folder
Answer
mark the above message as a solution by right clicking>mark solution
thx a lot !
Fetch api is best for next.js. Read https://adios-axios.com/
Oh wait my bad
you are using redaxios
which uses the fetch api
See if you can add additional options there for revalidate