Mastering TypeScript Generics for Better Code
Generics are the most powerful feature in TypeScript that most developers underuse. Once you internalize them, you'll write fundamentally safer abstractions.
Carlos Ruiz
Mar 14, 2026
Discover how Next.js 15 App Router and Route Handlers redefine the way we build fullstack APIs — from streaming responses to edge-ready endpoints.
Carlos Ruiz
Lead Engineer
The App Router introduced a fundamentally different model for building server-side logic in Next.js. With Route Handlers, you define API endpoints as co-located files alongside your pages, and you get the full power of Web APIs without any Node.js-only abstractions.
The old pages/api system was a thin wrapper over Node.js HTTP. Route Handlers, by contrast, are built on the Fetch API's Request and Response types. That means they run natively on the Edge, in serverless environments, and locally — all with the same code.
One of the most powerful features is first-class streaming support. You can return a ReadableStream directly, enabling real-time data delivery to your frontend.
export async function GET() {
const stream = new ReadableStream({
start(controller) {
controller.enqueue('data: hello
');
controller.close();
},
});
return new Response(stream, {
headers: { 'Content-Type': 'text/event-stream' },
});
}
Route Handlers participate in the same caching system as Server Components. Use export const revalidate = 60 to cache responses for 60 seconds, or export const dynamic = 'force-dynamic' for always-fresh data.
Carlos Ruiz
Lead Engineer a Lamio
Expert en enginyeria de programari modern amb enfocament en arquitectures escalables, optimització del rendiment i experiència del desenvolupador.
Generics are the most powerful feature in TypeScript that most developers underuse. Once you internalize them, you'll write fundamentally safer abstractions.
Carlos Ruiz
Mar 14, 2026
Rep les últimes perspectives d'enginyeria, tutorials i actualitzacions tecnològiques de l'equip Lamio.
Sense correu brossa, mai. Cancel·la la subscripció en qualsevol moment.