api

ETags for conditional requests and caching

ETags enable efficient caching by allowing clients to make conditional requests that return 304 Not Modified when content hasn't changed. Rails automatically generates ETags based on response content, and fresh_when or stale? methods handle the condit

GraphQL API with Spring Boot

GraphQL provides flexible APIs where clients specify exact data requirements. Spring for GraphQL integrates GraphQL Java with Spring Boot. Schema-first approach defines types in .graphqls files. Resolvers map schema fields to Java methods using @Query

Axios API client with interceptors

A centralized API client provides a single place to configure authentication, error handling, and request/response transformations. I use axios for its interceptor support and automatic JSON transformation. Request interceptors attach the JWT token fr

Django GraphQL with Graphene

Graphene brings GraphQL to Django. I define types mapping to models and create resolvers for queries and mutations. Clients request exactly the data they need, reducing over-fetching. I use DjangoObjectType for automatic schema generation from models.

Serializers with ActiveModel::Serializers

Controllers shouldn't know about JSON structure—that's a serialization concern. ActiveModel::Serializers (AMS) separates presentation from business logic by defining dedicated serializer classes for each model. Serializers specify exactly which attrib

API Pagination Headers (Link + Total)

Clients love predictable pagination. Provide Link headers and totals when feasible. This snippet shows a small helper that generates RFC5988-ish link headers for JSON endpoints.

Rails API versioning strategies

API versioning allows backward-incompatible changes without breaking existing clients. I version via URL path (/api/v1/posts) for simplicity and explicit version selection. Each version namespace has its own controllers and serializers. Routes use nam

Retrofit for REST API networking

Retrofit simplifies HTTP networking with type-safe API definitions. I define service interfaces with annotated methods—@GET, @POST, @PUT, @DELETE. Path parameters use @Path, query params use @Query, and request bodies use @Body. Retrofit converts resp

CORS configuration for cross-origin API requests

When building APIs consumed by frontend applications hosted on different domains, CORS (Cross-Origin Resource Sharing) headers are mandatory. The rack-cors gem simplifies configuration by letting me whitelist specific origins, HTTP methods, and header

Fetch API for HTTP requests and AJAX communication

The Fetch API provides modern interface for HTTP requests returning promises. I use fetch(url) to make GET requests that resolve with Response objects. The response.json() parses JSON data asynchronously. POST requests need method, headers, and body o

Streaming JSON decoding with DisallowUnknownFields

Large request bodies are where naive code falls over. Instead of io.ReadAll, I decode JSON incrementally with json.Decoder and enable DisallowUnknownFields so unexpected fields fail fast. That becomes a surprisingly strong safety net when you evolve A

Structured JSON error responses

Consistent error handling transforms debugging from guesswork into systematic troubleshooting. I use a rescue handler that catches exceptions globally and transforms them into a standard JSON structure containing an error code, human-readable message,