http

rust
use std::time::Duration;
use rand::Rng;

#[derive(Clone, Debug)]
pub struct BackoffPolicy {
    pub base_delay: Duration,

Exponential Backoff With Jitter for Retrying Fallible Async Operations in Rust

rust tokio async
by codesnips 3 tabs
go
package api

import "net/http"

func ETag(w http.ResponseWriter, r *http.Request, etag string) bool {
  w.Header().Set("ETag", etag)

ETag handling for conditional GETs (cheap caching)

go http caching
by Leah Thompson 1 tab
python
import random
from dataclasses import dataclass
from typing import Iterator


@dataclass(frozen=True)

Retry Flaky HTTP Requests with Exponential Backoff and Full Jitter in Python

python requests retry
by codesnips 3 tabs
go
package main

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

Graceful HTTP Server Shutdown in Go with SIGINT and Context Cancellation

go http graceful-shutdown
by codesnips 2 tabs
go
package middleware

import (
  "net/http"
)

CORS allowlist middleware (no wildcard surprises)

go http security
by Leah Thompson 1 tab
rust
use serde::{Deserialize, Deserializer};

#[derive(Debug, Deserialize)]
pub struct ListFilter {
    #[serde(default)]
    pub status: Status,

Parse URL Query Strings into a Typed Filter Struct with Defaults in Rust

rust serde query-string
by codesnips 3 tabs
ruby
require 'sinatra'
require 'json'
require_relative 'book'
require_relative 'helpers'

set :books, {

Sinatra Content Negotiation: Serve HTML or JSON by Accept Header

sinatra rack content-negotiation
by codesnips 4 tabs
go
package main

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

Instrumenting Go HTTP Handlers with Prometheus Counters and Histograms

prometheus metrics observability
by codesnips 3 tabs
ruby
require 'uri'
require 'rack/utils'

module PaginationLinks
  module_function

Cursor-Style Pagination With RFC 5988 Link Headers in Sinatra

sinatra pagination rest-api
by codesnips 3 tabs
go
package pricecache

import (
	"context"
	"sync"

Collapse Concurrent Identical Requests in Go with singleflight

go singleflight concurrency
by codesnips 3 tabs
go
package realtime

import (
  "fmt"
  "net/http"
  "time"

Server-Sent Events (SSE) with heartbeats and client cleanup

go http sse
by Leah Thompson 1 tab
typescript
import { NestFactory } from '@nestjs/core';
import { ValidationPipe } from '@nestjs/common';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

Global ValidationPipe with class-validator DTOs and Transform in NestJS

nestjs validation dto
by codesnips 3 tabs