Revalidating a GET endpoint in Next
Hey!
Does anyone know how to revalidate a cached GET endpoint in Next? With this basic code
cached/route.ts
reval/route.ts
cached-page/page.ts
The cached page revalidates fine, however the route handler does not.
even calling
revalidatePath("/", "layout")
which should revalidate everything only does so for the page.11 Replies
to make GET request dynamic you need to use
cookies()
or headers()
function
see the screennshot according. to nextjs docsso for your case -
cached/route.ts
reval/route.ts
- not required
cached-page/page.tsx
for the time being i am using cookies()
but you can also use headers()
as per your requirement ,both are exported from next/headers
yea I know you can make it dynamic like that but I want it to be static, but revalidate when the revalidatePath for it is called
so like ISR for pages
but seems like that's not possible for routes?
to be honest i amnot sure
but. surely you ca research and let. me. know
yeah I can not find anything about it
literally only thing I can find about it is
well you can't use revalidate with route handlers, the api doesn't exist yeton the next discord also find it so weird that nobody has run into this before, but maybe I just suck at googling
hi
have you tried this?https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#revalidating-data
Data Fetching: Fetching, Caching, and Revalidating | Next.js
Learn how to fetch, cache, and revalidate data in your Next.js application.
it. works for pages
not for routes
It does work for routes, but this is just an interval and not on demand like revalidatepath
oh i see