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
javascript
const express = require('express');
const { toCsv } = require('./csvSerializer');
const { fetchOrders } = require('./orderRepository');

const router = express.Router();

Content Negotiation in Express: Serve JSON or CSV From One Route

express content-negotiation rest-api
by codesnips 3 tabs
python
from typing import Any, Optional

from fastapi.responses import JSONResponse
from pydantic import BaseModel

Consistent JSON Error Responses in FastAPI With a Custom Exception Handler

fastapi error-handling exceptions
by codesnips 3 tabs
java
package com.example.ratelimit;

public class TokenBucket {

    private final long capacity;
    private final long refillTokens;

Per-Client Token Bucket Rate Limiting with a Spring Boot HandlerInterceptor

spring-boot rate-limiting token-bucket
by codesnips 4 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
go
package optimistic

import (
	"errors"
	"sync"
)

Optimistic UI Rollback in Go With a Compensating Action Log

go concurrency optimistic-ui
by codesnips 3 tabs
javascript
const { Pool } = require('pg');
const Cursor = require('pg-cursor');

const pool = new Pool();

async function* streamUsers({ since, batchSize = 500 }) {

Stream a Large JSON Array Response in Node.js Without Buffering

nodejs streams transform-stream
by codesnips 3 tabs