Next.js Discord

Discord Forum

My API is not working?

Unanswered
Tommy Kenton posted this in #help-forum
Open in Discord
In my localhost it will run the API every time I click the button but otherwise it will not when deployed to vercel? Please can someone help me...

22 Replies

@Tommy Kenton GET api route is cached by default in production
Simply change GET to POST if it's okay
@James4u Simply change GET to POST if it's okay
But then how do I GET something?
@James4u https://nextjs.org/docs/app/api-reference/functions/unstable_noStore
This worked would you recommend noStore or cookies?
noStore() unless you have something with cookie()
but I believe your real api is not gonna be only for getting random number, right?
you might end up using POST or reading cookie
still not, then noStore
@James4u you might end up using POST or reading cookie
Yes, I'm going to try make auth.
Then you probably need cookie(), right?
@James4u Then you probably need cookie(), right?
I'm not sure, I guess to store a user token or something?
store token? it should be from cookie or header, right?
if you use next/headers your api route will be fully dynamic even if it's GET` - so you won't need noStore()
@James4u, could you tell me if I'm experiencing the same problem? What's the best way to maintain GET?
https://nextjs-forum.com/post/1265350493585281156
@Lucas Bonafé your issue is not related to the cache I guess?
but I have a tip for you, you can run npm run start instead of npm run dev to run production server on your local.
@James4u but I have a tip for you, you can run `npm run start` instead of `npm run dev` to run production server on your local.
I've already tested with npm run dev and vercel dev, I just tested with npm run build and npm run start now and it worked normally, I'll try to configure the Vercel key without an escape in the $ that the ASAAS_API_KEY variable has...
Same error...
@James4u <@327558872892178434> your issue is not related to the cache I guess?
I have not yet tested the solutions described in the cache
Edit: Tested and not work...