http

go
package deps

import (
  "net/http"
  "time"

HTTP client middleware via RoundTripper (headers + timing)

go http client
by Leah Thompson 1 tab
go
package api

import (
  "io"
  "net/http"
)

Content sniffing for uploads (don't trust the header)

go http uploads
by Leah Thompson 1 tab
typescript
export class AppError extends Error {
  public readonly statusCode: number;
  public readonly code: string;
  public readonly isOperational: boolean;

  constructor(message: string, statusCode = 500, code = 'INTERNAL_ERROR', isOperational = true) {

Backend: normalize errors with a single Express handler

express error-handling typescript
by codesnips 4 tabs
typescript
export type CircuitState = "closed" | "open" | "half-open";

export interface CircuitBreakerOptions {
  failureThreshold: number;
  resetTimeout: number; // ms to wait in "open" before probing
  onStateChange?: (from: CircuitState, to: CircuitState) => void;

Circuit breaker wrapper for flaky third-party APIs

circuit-breaker resilience http
by codesnips 3 tabs
go
package api

import (
  "encoding/json"
  "net/http"
)

WriteJSON helper with consistent headers and status

go http json
by Leah Thompson 1 tab
php
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

Laravel middleware for request filtering

laravel middleware http
by Carlos Mendez 3 tabs
python
import time
import threading
from collections import deque, defaultdict


class SlidingWindowLimiter:

Sliding-Window Rate Limiting in Flask With a Custom Decorator and In-Memory Buckets

flask rate-limiting decorators
by codesnips 3 tabs
python
from typing import Optional
from pydantic import BaseModel, EmailStr, Field, field_validator, model_validator


class CreateUserRequest(BaseModel):
    model_config = {"extra": "forbid"}

Validating JSON Payloads with Pydantic v2 and Returning Field-Level Errors in FastAPI

fastapi pydantic validation
by codesnips 3 tabs
go
package main

import (
  "context"
  "log"
  "net/http"

Graceful shutdown: draining HTTP + background workers

go http shutdown
by Leah Thompson 1 tab
go
package main

import (
  "context"
  "net/http"
  "time"

HTTP server timeouts that prevent slowloris and stuck connections

go http reliability
by Leah Thompson 1 tab
php
<?php

namespace App\Exports;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Carbon;

Streaming a Filtered Orders CSV Export in Laravel with StreamedResponse

php laravel csv
by codesnips 3 tabs
typescript
const rawOrigins = process.env.ALLOWED_ORIGINS ?? "";

export const allowedOrigins = new Set(
  rawOrigins
    .split(",")
    .map((o) => o.trim())

CORS configuration that’s explicit (no *)

security http express
by codesnips 3 tabs