#api

30 snippets tagged with #api

typescriptintermediate

HTTP Client with Axios Interceptors

Pre-configured Axios instance with request/response interceptors for auth headers, logging, and retry logic.

Best for: Consuming third-party APIs

#axios#http
typescriptintermediate

Request Validation Schema Builder

Build a lightweight request validation layer with type inference for API endpoints.

Best for: API request body validation

#nodejs#validation
typescriptintermediate

Node.js Token Bucket Rate Limiter

Implement an in-memory token bucket rate limiter for controlling API request throughput.

Best for: Protecting APIs from abuse and DDoS

#nodejs#rate-limiting
typescriptbeginner

Native HTTP Server

Create a lightweight HTTP server using Node.js built-in http module with routing and JSON responses.

Best for: Lightweight API server without frameworks

#nodejs#http
typescriptbeginner

Fastify Server Setup

Create a high-performance Fastify server with schema validation, plugins, and typed routes.

Best for: High-performance REST APIs

#nodejs#fastify
typescriptadvanced

GraphQL Server with Type Definitions

Build a GraphQL API server with type definitions, resolvers, and query/mutation support.

Best for: GraphQL API development

#nodejs#graphql
typescriptintermediate

Webhook Handler with Signature Verification

Process incoming webhooks with HMAC signature verification, replay protection, and idempotency.

Best for: GitHub/Stripe webhook processing

#nodejs#webhook
typescriptintermediate

Cursor-Based Pagination API

Implement cursor-based pagination with forward/backward navigation, consistent ordering, and link headers.

Best for: REST API pagination

#nodejs#pagination
typescriptintermediate

API Versioning Strategy

Implement API versioning with URL path, header-based, and content negotiation strategies.

Best for: API backward compatibility

#nodejs#api
typescriptadvanced

Idempotency Key Middleware

Prevents duplicate request processing by caching responses keyed by the Idempotency-Key header.

Best for: Payment processing

#idempotency#api
typescriptadvanced

OpenAPI Request Validator

Validates incoming request body against a JSON schema derived from an OpenAPI spec.

Best for: API input validation

#openapi#validation
typescriptadvanced

Sliding Window Rate Limiter

Implements sliding window rate limiting that distributes limits more evenly than fixed windows.

Best for: API rate limiting

#rate-limiting#security
typescriptadvanced

Optimistic Update Pattern

Apply UI changes immediately before server confirmation with automatic rollback on failure.

Best for: Like/upvote buttons

#optimistic-update#state
typescriptintermediate

useMutation Hook for Side Effects

Handle mutations (POST/PUT/DELETE) with loading, error, reset, and optimistic update support.

Best for: Form submission handling

#react#hooks
typescriptintermediate

Type-Safe API Route Handler

Next.js App Router route handler with input validation, typed responses, and proper error handling.

Best for: CRUD API endpoints

#api#route-handler
typescriptadvanced

Streaming API Response

Stream long-running API responses using ReadableStream and TransformStream for real-time data delivery.

Best for: AI response streaming

#streaming#api
typescriptintermediate

Next.js Route Handlers (API Routes)

Build RESTful API endpoints using Next.js App Router route handlers with typed responses.

Best for: Building REST APIs within a Next.js application

#nextjs#api
typescriptintermediate

API Route Rate Limiting

Add rate limiting to Next.js API routes with sliding window, IP-based limits, and custom responses.

Best for: API abuse prevention

#nextjs#api
typescriptbeginner

Route Handler Response Helpers

Common response patterns for Next.js route handlers with proper status codes and headers.

Best for: API route handlers

#nextjs#api
typescriptintermediate

Route Handler with CORS Support

Add CORS headers to Next.js route handlers for cross-origin API access.

Best for: external API consumers

#nextjs#cors
typescriptadvanced

Webhook Handler with Signature Verification

Handle incoming webhooks with signature verification and idempotent processing.

Best for: payment webhooks

#nextjs#webhooks
pythonintermediate

FastAPI Dependency Injection

Use FastAPI's dependency injection for database sessions, auth checks, and shared service logic.

Best for: Database session management

#fastapi#dependency-injection
pythonbeginner

Mistral AI API Client in Python

Make chat and embedding requests to Mistral AI using the official Python SDK.

Best for: European AI compliance

#mistral#llm
pythonintermediate

BentoML Model Serving Service

Package and serve a scikit-learn model as a REST API with BentoML in Python.

Best for: model deployment

#bentoml#model-serving
typescriptintermediate

Vercel API — Trigger and List Deployments

Use the Vercel REST API to trigger deployments, list recent builds, and check deployment status.

Best for: Triggering deployments from CI or Slack bots

#vercel#api
javaadvanced

Rate Limiter — Token Bucket Algorithm

Implement a thread-safe rate limiter using the token bucket algorithm for API throttling.

Best for: API rate limiting per user or IP

#java#rate-limiting
javaintermediate

Java Built-in HTTP Server

Create a lightweight HTTP server with com.sun.net.httpserver: routing, JSON responses, file serving.

Best for: Lightweight HTTP servers for testing and prototyping

#java#http
javaintermediate

Spring Boot — RestClient HTTP Calls

Make HTTP requests with Spring RestClient (6.1+): GET, POST, error handling, interceptors, and timeouts.

Best for: REST API consumption in Spring Boot services

#spring-boot#rest-client
scalaintermediate

HTTP Client with sttp

Make HTTP requests with sttp: GET, POST, headers, JSON bodies, and async backends.

Best for: REST API integration

#scala#http
scalaadvanced

Tapir Type-Safe API Endpoints

Define and serve HTTP API endpoints with Tapir: type-safe inputs, outputs, error handling, and docs.

Best for: Type-safe HTTP API definitions

#scala#tapir