Functions

Pages Router on-demand regeneration

Pages API response supports res.revalidate for an actual getStaticProps path. This partial helper requires an already verified authorization decision supplied by a trusted server caller and checks POST before requesting the fixed path. Return success only after the operation resolves. Treat failure as unknown freshness and log safely in the real application. Not a complete public endpoint. Source: https://nextjs.org/docs/pages/guides/incremental-static-regeneration. Documentation-reviewed illustrative draft; installed declarations and runtime not verified.

Formal Syntax & Structure

nextjs syntaxnextjs
await res.revalidate(urlPath)

Working Example

Example Snippetnextjs
import type {NextApiRequest,NextApiResponse} from 'next';export async function refreshReviewedPage(req:NextApiRequest,res:NextApiResponse,authorized:boolean){ res.setHeader('Cache-Control','no-store'); if(req.method!=='POST'){res.setHeader('Allow','POST');res.status(405).end();return;} if(!authorized){res.status(403).end();return;} try{await res.revalidate('/catalog/moss');res.status(200).json({ok:true});} catch{res.status(503).json({error:'Regeneration not confirmed'});}}
Next.js Reference