Frontend call external API with Axiox
Answered
melvin_vga posted this in #help-forum
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
- With fetch api, you can easily control the cache
- The issue was fixed by deleting the
- 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 folder34 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?
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/eventmy 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 🙏
Before I help: https://adios-axios.com/
@melvin_vga 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
I dont think think baseUrl should be there
@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
but not logs on my backend
can you try deleting
.next folder and restarting the app?@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
- With fetch api, you can easily control the cache
- The issue was fixed by deleting the
- 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 folderAnswer
mark the above message as a solution by right clicking>mark solution
thx a lot !
@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
you recommended that I use fetch rather than the Ky library?
Fetch api is best for next.js. Read https://adios-axios.com/
Oh wait my bad
you are using
redaxioswhich uses the fetch api
See if you can add additional options there for revalidate