Code Explainers
Browse the library
java
package com.example.monitoring; import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.HealthIndicator;
A custom replica health check in Spring
health-check
actuator
monitoring
Intermediate
7 steps
javascript
import { NextResponse } from 'next/server'; import Stripe from 'stripe'; import { headers } from 'next/headers';
Handling Stripe webhooks in Next.js
webhooks
signature verification
payment processing
Intermediate
7 steps
go
func StreamMetrics(c *gin.Context) { clientGone := c.Request.Context().Done() ticker := time.NewTicker(time.Second) defer ticker.Stop()
Streaming server-sent events in Gin
server-sent-events
streaming
channels
Intermediate
7 steps
php
<?php namespace App\Http\Middleware;
Enforcing a JSON Accept header in Laravel
middleware
content-negotiation
http-headers
Beginner
5 steps
python
from fastapi import APIRouter, Depends, Query from pydantic import BaseModel from sqlalchemy import func, select from sqlalchemy.ext.asyncio import AsyncSession
How a paginated list endpoint works in FastAPI
pagination
dependency-injection
async-orm
Intermediate
8 steps
javascript
const fs = require('fs'); const path = require('path'); router.get('/downloads/:name', (req, res, next) => {
Streaming file downloads in Express
streaming
backpressure
file-download
Advanced
9 steps
ruby
module Retryable class RetriesExhausted < StandardError; end RETRYABLE_ERRORS = [
Exponential backoff retries in Ruby
retry-logic
exponential-backoff
error-handling
Intermediate
7 steps
typescript
import { IsEmail, IsEnum, IsInt, IsOptional, IsString, Length, Max, Min } from 'class-validator'; import { Type } from 'class-transformer'; import { Body, Controller, Post } from '@nestjs/common';
How DTO validation works in NestJS
validation
data-transfer-objects
decorators
Intermediate
8 steps
go
package worker import ( "fmt"
A graceful worker pool in Go
concurrency
goroutines
channels
Intermediate
7 steps
java
@Repository public interface OrderRepository extends JpaRepository<Order, Long> { @QueryHints(@QueryHint(name = HINT_FETCH_SIZE, value = "1000"))
Streaming large result sets in Spring Data JPA
streaming
jpa
memory-management
Advanced
6 steps
javascript
async function pollJobUntilComplete(jobId, { interval = 2000, timeout = 60000, signal } = {}) { const deadline = Date.now() + timeout; while (true) {
Polling a job until it finishes in JavaScript
polling
async-await
abortsignal
Intermediate
6 steps
ruby
class Throttle def initialize(interval) @interval = interval @mutex = Mutex.new
A thread-safe throttle in Ruby
concurrency
rate-limiting
mutex
Intermediate
7 steps
typescript
type CheckoutState = "cart" | "shipping" | "payment" | "review" | "confirmed"; type CheckoutEvent = | { type: "PROCEED" }
A typed checkout state machine in TypeScript
state-machine
union-types
type-safety
Intermediate
7 steps
go
package handlers import ( "net/http"
Rendering HTML pages with Gin handlers
http-handlers
templating
error-handling
Beginner
8 steps
rust
use axum::{ body::Body, extract::Path, http::{header, StatusCode},
Streaming file downloads in Axum
streaming
file-serving
path-traversal
Intermediate
8 steps
java
import java.util.ArrayList; import java.util.Comparator; import java.util.HashSet; import java.util.List;
Three ways to deduplicate a list by key in Java
streams
deduplication
collectors
Intermediate
6 steps
php
<?php function verifyJwt(string $token, string $secret): array {
Verifying an HS256 JWT in PHP
jwt
hmac
authentication
Intermediate
9 steps
python
from fastapi import FastAPI, Request, status from fastapi.responses import JSONResponse app = FastAPI()
Custom exception handlers in FastAPI
exception handling
error responses
separation of concerns
Intermediate
7 steps