add-api-route

Create Next.js API routes that proxy to backend services with authentication and caching.

4|2|Updated Oct 26, 2025
One-click install
npx skills add https://github.com/nomos-guild/cgov --skill add-api-route
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: add-api-route
Source: https://github.com/nomos-guild/cgov/tree/main/.claude/skills/add-api-route
Command: npx skills add https://github.com/nomos-guild/cgov --skill add-api-route

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill addresses the boilerplate of exposing backend services through Next.js API routes by providing a consistent pattern for authenticated proxies, error handling, and caching.

Core Features & Use Cases

  • API proxying: Create routes that forward requests to a backend service with proper error handling and retries.
  • Server-side aggregation: Build endpoints that fetch and combine data from multiple sources to reduce frontend complexity.
  • Security & caching: Centralize authentication, rate limiting, and set caching headers to improve performance for frontend apps.
  • Use Case: Example: expose a votes tally endpoint at /api/votes/tally that proxies to the internal API and caches responses for 60 seconds.

Quick Start

Use the add-api-route skill to scaffold a new Next.js API route at src/pages/api/voters/stats.ts that proxies to /api/voters/statistics with caching.

Frequently Asked Questions about add-api-route

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a Next.js API route that proxies to a backend with authentication and caching?

You can scaffold a Next.js API route to proxy backend requests by generating files at src/pages/api/ and integrating with a central apiHelper that manages authentication, error handling, and cache headers. This pattern securely exposes backend services to your frontend.

What is the best way to aggregate data from multiple backend endpoints in a Next.js API route?

Aggregating data from multiple backend endpoints in a Next.js API route reduces frontend complexity by building a single server-side proxy endpoint. This approach fetches and combines responses securely before returning the aggregated payload to the client application.

How do I set up caching headers for Next.js API routes?

Setting up caching headers for Next.js API routes involves configuring the response headers within your route handler. This skill configures cache headers to cache proxy responses for specified durations, such as 60 seconds, improving frontend application performance.

Does this API proxy pattern support dynamic routes in Next.js?

Yes, the API proxy pattern supports dynamic routes in Next.js. It generates files at src/pages/api/${$0}.ts or src/pages/api/${$0}/index.ts, allowing you to create dynamic route segments that securely forward requests to backend services.

How do I handle errors when proxying requests through a Next.js API route?

Handling errors when proxying requests through a Next.js API route requires a centralized pattern for robust error handling and retries. This skill integrates with an apiHelper to catch upstream backend failures and return consistent error responses to the frontend.

When should I use a Next.js API route as a server-side proxy instead of calling the backend directly?

Use a Next.js API route as a server-side proxy when you need to centralize authentication, implement rate limiting, or apply caching headers. This pattern exposes third-party services securely for frontend consumption without exposing raw backend endpoints.