http

typescript
import { z } from "zod";

const coerceNumber = z.preprocess((v) => {
  if (v === "" || v === undefined) return undefined;
  if (typeof v !== "string") return v;
  const n = Number(v);

API input coercion for query params (Zod preprocess)

typescript validation api
by codesnips 3 tabs
go
package authtransport

import (
	"errors"
	"net/http"
)

Injecting Auth Headers via a Custom http.RoundTripper Decorator in Go

go http middleware
by codesnips 3 tabs
go
package web

import (
	"embed"
	"io/fs"
)

Serve Embedded Static Assets with embed.FS and Cache Headers in Go

go embed static-assets
by codesnips 3 tabs
go
package main

import (
	"log"
	"net/http"
	"time"

Serving Partial Video Content with HTTP Range Requests in Go

go http range-requests
by codesnips 3 tabs
ruby
class CircuitBreaker
  class CircuitOpenError < StandardError; end

  def initialize(name, redis: Redis.current, failure_threshold: 5, failure_window: 60, cooldown: 30)
    @key = "circuit:#{name}"
    @redis = redis

Service-Level “Circuit Breaker” (Simple)

rails reliability http
by codesnips 3 tabs
go
package webhooks

import (
  "bytes"
  "crypto/hmac"
  "crypto/sha256"

Webhook signature verification with HMAC (timing-safe compare)

go security http
by Leah Thompson 1 tab
javascript
const RETRYABLE_STATUS = new Set([408, 429, 500, 502, 503, 504]);

export function fullJitter(attempt, baseDelay = 300, maxDelay = 10_000) {
  const ceiling = Math.min(maxDelay, baseDelay * 2 ** attempt);
  return Math.random() * ceiling;
}

Fetch With Exponential Backoff and Full Jitter Retries

fetch retry exponential-backoff
by codesnips 3 tabs