api-layer-patterns

Implement a three-layer API pattern for Next.js apps with HMAC signing.

2|Updated Apr 9, 2023
One-click install
npx skills add https://github.com/Esdeveniments/esdeveniments-frontend --skill api-layer-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: api-layer-patterns
Source: https://github.com/Esdeveniments/esdeveniments-frontend/tree/main/.github/skills/api-layer-patterns
Command: npx skills add https://github.com/Esdeveniments/esdeveniments-frontend --skill api-layer-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill codifies a secure three-layer API pattern to prevent direct external API calls from client code, ensuring internal routes, wrappers, and guards control all data flows.

Core Features & Use Cases

  • Layered architecture: Client code ⇢ internal API routes ⇢ external wrappers, with a clear separation of concerns.
  • Safety and resilience: env guards, HMAC signing, runtime validation, and safe fallbacks across layers.
  • Use Case: When adding a new backend resource, implement an internal route that proxies to the external API with server-side signing and caching.

Quick Start

Follow repo templates and guidelines to implement a new API resource using the three-layer pattern (client library → internal route → external wrapper).

Frequently Asked Questions about api-layer-patterns

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

FAQPage Schema
How do I secure external API calls in Next.js so secrets are not exposed to the client?

To secure external API calls in Next.js, route client requests through internal API routes acting as a proxy, enabling server-side HMAC signing and environment variable guards before forwarding data to the external API.

What is the three-layer API pattern for backend data fetching?

The three-layer API pattern structures data fetching by separating client code, internal API routes, and external API wrappers. This enforces clear boundaries, ensuring all external requests pass through guarded internal proxies.

How do I implement HMAC signing for an internal API proxy?

Implement HMAC signing for an internal API proxy within a Next.js API route by intercepting the client request, applying the signature server-side using stored secrets, and forwarding the signed request to the external wrapper.

When should I use an API proxy pattern instead of calling external APIs directly?

Use an API proxy pattern when adding new backend resources that require server-side caching, runtime validation, or HMAC signing. It prevents direct external calls from client code, ensuring safe fallbacks and env guards control data flows.

How do I add environment variable guards to Next.js API routes?

Add environment variable guards to Next.js API routes by enacting an env check at the start of the internal route layer. This ensures the external wrapper only attempts data fetching if required configuration secrets are present.