Next.js Discord

Discord Forum

RouteHandlers Caching (POST)

Unanswered
Transvaal lion posted this in #help-forum
Open in Discord
Transvaal lionOP
Hi everyone.

I use Route Handlers to fetch data via POST from an external API (GET isn't possible). The data isn't updated too often and can be cached. I want to refetch every 24h. I read the [documentation](https://nextjs.org/docs/app/building-your-application/routing/route-handlers) and it says GET is cached by default, but POST will be evaluated dynamically. I'm not sure how to understand that. Will my fetch including revalidate work? Do you have any pointers for me?

export async function POST(request: Request) { const token = process.env.KLARNA_TOKEN; const { country, pagination } = await request.json(); const res = await fetch( "https://universe.openbanking.klarna.com/v2/banks/list", { method: "POST", headers: { Authorization:Token ${process.env.KLARNA_TOKEN}, "Content-Type": "application/json", }, body: JSON.stringify({ country: country, pagination: pagination, }), next: { revalidate: 60 * 60 * 24 }, }, ); const data = await res.json(); return Response.json(data); }

0 Replies