Skip to content
StackPractices

Tag: api

Browse 66 practical software engineering resources tagged with "api". Discover code recipes, design patterns, documentation templates, and in-depth guides to help you build, deploy, and maintain production-ready solutions involving api.

Create API Documentation with OpenAPI

Generate interactive API docs from OpenAPI specs using Swagger UI, Redoc, and native tools in Python, JavaScript, and Java.

Implement API Logging and Audit Trails

Set up thorough request/response logging and audit trails for APIs with structured output, correlation IDs, and compliance considerations.

API Rate Limiting

Protect APIs from abuse and ensure fair resource usage with token bucket, sliding window, and leaky bucket rate limiting.

Implement API Rate Limiting with Redis

Protect APIs from abuse using token bucket and sliding window algorithms with Redis, including burst handling, distributed coordination, and custom headers for client feedback

API Versioning

How to version REST and GraphQL APIs to maintain backward compatibility while evolving your interface.

Call a REST API

How to make HTTP requests to a REST API and handle the JSON response in multiple languages.

Cursor-Based Pagination with PostgreSQL

Implement efficient cursor-based pagination for large datasets in PostgreSQL, avoiding OFFSET performance degradation with indexed keyset pagination and stable sort ordering

Express.js Middleware Composition Patterns

Build maintainable Express applications using middleware composition patterns for authentication, validation, error handling, request context propagation, and async route wrappers

Go REST API with Gin and Middleware

Build production-ready REST APIs in Go using the Gin framework with custom middleware for logging, authentication, validation, and error handling

Implement a GraphQL API

Build a production-ready GraphQL API with type-safe schemas, resolvers, and query optimization in Python, JavaScript, and Java.

Build a GraphQL API with Apollo Server and TypeScript

How to build a production-ready GraphQL API using Apollo Server, TypeScript, and DataLoader to solve the N+1 query problem

Implement a gRPC API with Protocol Buffers

How to implement a gRPC API using Protocol Buffers for high-performance service-to-service communication

gRPC Services with Protocol Buffers in TypeScript

Build high-performance, strongly-typed services using gRPC with Protocol Buffers, covering unary calls, server streaming, client streaming, and bidirectional streaming

Handle CORS Correctly

How to configure Cross-Origin Resource Sharing (CORS) headers correctly for APIs, SPAs, and serverless functions without opening security holes.

Handle Errors in APIs

Patterns for consistent, predictable API error handling across multiple languages and frameworks.

Idempotent API Endpoints

How to design and implement idempotent API endpoints that safely handle retries, duplicate requests, and network failures without side effects.

Input Validation

How to validate user input safely using schemas, type checking, and sanitization across Python, JavaScript, and Java.

Logging

How to implement structured, level-based logging across Python, JavaScript, and Java with what works for production observability.

Middleware

How to implement request/response middleware for logging, auth, and error handling across Python, JavaScript, and Java.

Configure Nginx as a Reverse Proxy and API Gateway

How to use Nginx as a reverse proxy for backend services, implement load balancing, SSL termination, and rate limiting for production API gateways

Pagination

How to implement cursor-based and offset-based pagination in APIs and databases across Python, JavaScript, and SQL.

Rate Limiting

How to implement API rate limiting using token bucket, sliding window, and fixed window algorithms across Python, JavaScript, and Java.

Build Real-Time Notifications with WebSockets

Implement a real-time notification system using WebSockets and Redis pub/sub for broadcasting messages across clients.

REST API Design: What Works

Design reliable, scalable REST APIs with proper HTTP methods, status codes, versioning, and pagination strategies.

Send Emails with SMTP

How to send transactional and bulk emails securely using SMTP with template support.

Server-Sent Events (SSE)

How to implement one-way real-time streaming from server to browser using Server-Sent Events, with reconnection, event types, and multi-client broadcasting.

Implement Server-Sent Events in Go for Real-Time Updates

How to build a production-ready Server-Sent Events endpoint in Go with connection management, heartbeat pings, and graceful client disconnect handling

Server-Sent Events with Node.js and Express

Implement real-time server-to-client push using Server-Sent Events in Node.js with Express, covering connection management, event types, reconnection logic, and backpressure handling

Webhooks

How to create and consume webhook endpoints for real-time event-driven integrations.

WebSocket Authentication and Security Patterns

How to authenticate WebSocket connections, implement token validation, and handle authorization for real-time messaging in production

Build a Bidirectional Chat with WebSocket and Node.js

How to build a real-time bidirectional chat application using WebSocket with room-based messaging, presence tracking, and message persistence

WebSocket Server

How to build a WebSocket server for bidirectional real-time communication, with connection management, message broadcasting, and heartbeat keepalive.

Rate Limiting with Redis Token Bucket Algorithm

Implement a distributed token bucket rate limiter using Redis atomic operations for API throttling across multiple server instances

Custom GraphQL Scalar Types for Dates, Emails, and JSON

Define custom GraphQL scalars for Date, Email, URL, and JSON fields with serialization, parsing, and validation logic

Cursor-based Pagination with GraphQL Relay Connections

Implement Relay-style cursor pagination in GraphQL with edges, nodes, and pageInfo for efficient forward and backward traversal

Prometheus API Monitoring

Monitor API performance and health with Prometheus metrics, custom collectors, and alerting rules.

Load Testing APIs with k6 and Threshold-Based Assertions

How to write and run load tests with k6 to measure API performance, validate SLOs, and identify bottlenecks before production deployment

HMAC Request Signing

Secure API requests with HMAC-SHA256 signatures to ensure integrity and authenticity.

Test Express APIs with supertest

How to test Express.js REST API endpoints end-to-end using supertest, including status codes, JSON bodies, headers, authentication, and error handling.

Backends for Frontends: Dedicated Backend per Client Type

How to create dedicated backends per client type. Covers BFF for web, mobile, and desktop. Covers API aggregation, client-specific optimization, and GraphQL BFF.

Adapter Pattern for Integrating External REST APIs

Use the Adapter pattern to normalize responses from external REST APIs into a consistent internal model without leaking third-party formats into your domain

Backend for Frontend (BFF) Pattern

Create dedicated backend services tailored to the specific needs of each frontend client type, aggregating downstream APIs and optimizing data shapes per platform.

Facade Pattern

Provide a simplified interface to a complex subsystem. A structural pattern that hides implementation details behind a clean API.

Contract Testing: Verify Consumer-Producer API Contracts

How to use contract testing to verify that API producers and consumers agree on request and response shapes. Covers Pact consumer-driven contracts and provider verification.

API Changelog Template

A template for documenting API changes including breaking changes, new features, deprecations, and bug fixes.

API Deprecation Notice Template

A template for communicating API deprecations, breaking changes, and sunset timelines to consumers.

API Error Handling Guideline

A guideline for standardizing error responses, status codes, and error payloads across REST and GraphQL APIs.

API Rate Limiting Policy Template

A template for defining API rate limits per consumer tier, including burst allowances, quota periods, and escalation paths.

API Lifecycle Management Template

A checklist template for API deprecation, versioning, and sunset procedures.

API Monitoring & Alerting Template

A template for defining API SLA thresholds, error rate alerts, and monitoring dashboards.

API Performance Budget Template

A template for setting and tracking API latency and throughput performance budgets.

Microservice Contract Template

A template for defining service contracts and API agreements between microservices.

Component API Documentation Template

A template for documenting UI component APIs: props, events, slots, methods, accessibility, and usage examples with TypeScript types.

API Security Review Template

A checklist template for reviewing API authentication, rate limiting, and OWASP compliance.

API Documentation Template

A reusable template for documenting REST and GraphQL APIs with endpoints, schemas, errors, and examples.

API Error Response Template

A reusable template for consistent, informative, and developer-friendly API error responses that reduce debugging time.

API Status Page Template

A template for a public API status page that communicates uptime, incidents, and maintenance windows to consumers.

API Testing Strategy Template

A template for planning contract tests, integration tests, and load tests for APIs.

Complete Guide to OpenAI API Mastery

Master the OpenAI API in production. Covers chat completions, streaming, function calling, structured outputs, embeddings, fine-tuning, batch API, assistants API, rate limits, error handling, and cost optimization patterns.

Complete Guide to GraphQL Federation

Build unified GraphQL APIs across multiple services with Apollo Federation. Covers subgraphs, supergraph composition, entity resolution, and gateway deployment.

REST API Design Guide

A thorough guide to designing clean, scalable, and maintainable REST APIs.

GraphQL vs REST — When to Choose and How to Migrate

A decision guide comparing GraphQL and REST APIs: use cases, performance, caching, tooling, and migration strategies for engineering teams.

API Security Checklist — Authentication to Encryption

A thorough security checklist for APIs: authentication, authorization, input validation, rate limiting, encryption, logging, and deployment hardening.

CORS Security: Origins, Headers, Preflight, Credentials

Master CORS security: same-origin policy, CORS headers, preflight requests, credential handling, common misconfigurations, and production security patterns for web APIs.

Web Application Security (OWASP Top 10)

A developer-focused guide to the OWASP Top 10: injection, broken access control, XSS, insecure design, and how to prevent each vulnerability with code examples.

Webhook Security — Delivery, Verification, and Protection

A practical guide to securing webhooks: signature verification, replay attack prevention, payload encryption, and endpoint hardening for reliable delivery.