Real-time data fetch
Answered
Erenay posted this in #help-forum
![Avatar](https://cdn.discordapp.com/avatars/1029431477219360869/8b992c76ffead0f5ac0be90e9fbd9b66.webp?size=256)
ErenayOP
Whenever I make a request to the API, I get the data from when I built my application. how do I get real-time data?
(translator used)
(translator used)
Answered by Erenay
i solved the problem. i added this at the beginning of all route files.
export const dynamic = 'force-dynamic';
export const revalidate = 0;`
13 Replies
![Avatar](https://cdn.discordapp.com/avatars/1029431477219360869/8b992c76ffead0f5ac0be90e9fbd9b66.webp?size=256)
@Erenay Whenever I make a request to the API, I get the data from when I built my application. how do I get real-time data?
(translator used)
![Avatar](https://cdn.discordapp.com/avatars/301376057326567425/788b75eb8862277af3d31d317ada783f.webp?size=256)
what do you want to archive? Why do you want "real time"?
![Avatar](https://cdn.discordapp.com/avatars/301376057326567425/788b75eb8862277af3d31d317ada783f.webp?size=256)
@B33fb0n3 what do you want to archive? Why do you want "real time"?
![Avatar](https://cdn.discordapp.com/avatars/1029431477219360869/8b992c76ffead0f5ac0be90e9fbd9b66.webp?size=256)
ErenayOP
I make a POST request to the API and create a data in the database and then when I try to retrieve the data with a GET request, I get the data of the application when it was built (ie null because there is no such data). but it seems to be created in the database.
which one should I use
![Avatar](https://cdn.discordapp.com/avatars/1029431477219360869/8b992c76ffead0f5ac0be90e9fbd9b66.webp?size=256)
@Erenay I make a POST request to the API and create a data in the database and then when I try to retrieve the data with a GET request, I get the data of the application when it was built (ie null because there is no such data). but it seems to be created in the database.
![Avatar](https://cdn.discordapp.com/avatars/301376057326567425/788b75eb8862277af3d31d317ada783f.webp?size=256)
which nextjs version are you using?
![Avatar](https://cdn.discordapp.com/avatars/1029431477219360869/8b992c76ffead0f5ac0be90e9fbd9b66.webp?size=256)
@Erenay 14.2.18
![Avatar](https://cdn.discordapp.com/avatars/301376057326567425/788b75eb8862277af3d31d317ada783f.webp?size=256)
then your GET route handlers are cached by default. You need to revalidate them after you made a change. You can revalidate by path like:
You call that function after you inserted your data.
revalidatePath("/api/whatever/route")
You call that function after you inserted your data.
![Avatar](https://cdn.discordapp.com/avatars/301376057326567425/788b75eb8862277af3d31d317ada783f.webp?size=256)
@B33fb0n3 then your GET route handlers are cached by default. You need to revalidate them after you made a change. You can revalidate by path like:
revalidatePath("/api/whatever/route")
You call that function after you inserted your data.
![Avatar](https://cdn.discordapp.com/avatars/1029431477219360869/8b992c76ffead0f5ac0be90e9fbd9b66.webp?size=256)
ErenayOP
Isn't there a shorter way to set this in the config file etc.?
![Avatar](https://cdn.discordapp.com/avatars/1029431477219360869/8b992c76ffead0f5ac0be90e9fbd9b66.webp?size=256)
@Erenay Isn't there a shorter way to set this in the config file etc.?
![Avatar](https://cdn.discordapp.com/avatars/301376057326567425/788b75eb8862277af3d31d317ada783f.webp?size=256)
Upgrade to nextjs15 and it's solved as well. In next15 the GET routes are not cached by default 🤷♂️
![Avatar](https://cdn.discordapp.com/avatars/301376057326567425/788b75eb8862277af3d31d317ada783f.webp?size=256)
@B33fb0n3 Upgrade to nextjs15 and it's solved as well. In next15 the GET routes are not cached by default 🤷♂️
![Avatar](https://cdn.discordapp.com/avatars/1029431477219360869/8b992c76ffead0f5ac0be90e9fbd9b66.webp?size=256)
ErenayOP
next.js gives error even though I useSearchParams in v15. that's why I use v14 unfortunately.
![Avatar](https://cdn.discordapp.com/avatars/1029431477219360869/8b992c76ffead0f5ac0be90e9fbd9b66.webp?size=256)
@Erenay next.js gives error even though I useSearchParams in v15. that's why I use v14 unfortunately.
![Avatar](https://cdn.discordapp.com/avatars/301376057326567425/788b75eb8862277af3d31d317ada783f.webp?size=256)
yea, I thought about you get other errors when you upgrade to v15. So in my opinion I would add the
revalidatePath
to the function that POST the data![Avatar](https://cdn.discordapp.com/avatars/301376057326567425/788b75eb8862277af3d31d317ada783f.webp?size=256)
@B33fb0n3 yea, I thought about you get other errors when you upgrade to v15. So in my opinion I would add the revalidatePath to the function that POST the data
![Avatar](https://cdn.discordapp.com/avatars/1029431477219360869/8b992c76ffead0f5ac0be90e9fbd9b66.webp?size=256)
ErenayOP
i solved the problem. i added this at the beginning of all route files.
export const dynamic = 'force-dynamic';
export const revalidate = 0;`
Answer
![Avatar](https://cdn.discordapp.com/avatars/1029431477219360869/8b992c76ffead0f5ac0be90e9fbd9b66.webp?size=256)
@Erenay i solved the problem. i added this at the beginning of all route files.
js
export const dynamic = 'force-dynamic';
export const revalidate = 0;`
![Avatar](https://cdn.discordapp.com/avatars/301376057326567425/788b75eb8862277af3d31d317ada783f.webp?size=256)
keep in mind, that none of your data is then cached and your usage will go to the moon if you use it to much