Next.js Discord

Discord Forum

Route Handlers

Unanswered
Peterbald posted this in #help-forum
Open in Discord
PeterbaldOP
Does the code below mean that the endpoint /api/items/hub is static, and revalidated and updated every minute?
// src/app/api/items/[slug]/route.ts
export async function GET(
  _: Request,
  { params }: { params: { slug: string } },
) {
  const res = await fetch(`https://api.example.com/items/${params.slug}`, {
    next: { revalidate: 60 },
  });
  const data = await res.json();

  return Response.json(data);
}

2 Replies

PeterbaldOP
I use Next.js 13.4
@Peterbald Does the code below mean that the endpoint `/api/items/hub` is static, and revalidated and updated every minute? // src/app/api/items/[slug]/route.ts export async function GET( _: Request, { params }: { params: { slug: string } }, ) { const res = await fetch(`https://api.example.com/items/${params.slug}`, { next: { revalidate: 60 }, }); const data = await res.json(); return Response.json(data); }
I think its static, try this
// src/app/api/items/[slug]/route.ts

export const revalidate = 60;

export async function GET(
  _: Request,
  { params }: { params: { slug: string } },
) {
  const res = await fetch(`https://api.example.com/items/${params.slug}`);
  const data = await res.json();

  return Response.json(data);
}