http

python
import csv


class _LineBuffer:
    def __init__(self):
        self._data = ""

Stream a Large CSV Export in Chunks from a Flask Endpoint

flask streaming csv
by codesnips 3 tabs
typescript
import type { Redis } from "ioredis";

export interface StoredResponse {
  status: "pending" | "completed";
  fingerprint: string;
  httpStatus?: number;

Idempotent POST Requests in Express with a Redis-Backed Middleware

express redis idempotency
by codesnips 3 tabs
python
from sqlalchemy import select
from sqlalchemy.orm import Session

from .models import User

BATCH_SIZE = 1000

Stream a Large CSV Export in FastAPI With StreamingResponse and a Generator

fastapi streaming csv
by codesnips 3 tabs
go
package metrics

import (
  "net/http"
  "strconv"
  "time"

Prometheus metrics middleware capturing status + duration

go prometheus metrics
by Leah Thompson 1 tab
rust
use std::time::Instant;

use axum::{
    extract::Request,
    http::HeaderValue,
    middleware::Next,

Axum Latency Logging Middleware With Request IDs and Tracing Spans

axum tower middleware
by codesnips 2 tabs
java
package com.example.api.error;

import com.fasterxml.jackson.annotation.JsonInclude;

import java.time.Instant;
import java.util.List;

Consistent JSON Error Responses with @RestControllerAdvice in Spring Boot

spring-boot rest-api error-handling
by codesnips 4 tabs
ruby
module BoundedFanOut
  Result = Struct.new(:value, :error) do
    def ok?
      error.nil?
    end
  end

Parallelize Independent External Calls (in a bounded way)

concurrency threads http
by codesnips 3 tabs
lua
local key = KEYS[1]
local capacity = tonumber(ARGV[1])
local rate = tonumber(ARGV[2])
local now = tonumber(ARGV[3])
local ttl = tonumber(ARGV[4])

Redis-Backed Token Bucket Rate Limiter with Lua Atomic Refill in Go

rate-limiting token-bucket redis
by codesnips 3 tabs
typescript
import { AxiosError } from 'axios';

export const RETRY_CONFIG = {
  maxRetries: 4,
  baseDelayMs: 200,
  maxDelayMs: 5_000,

Exponential-Backoff Retry Interceptor Around NestJS HttpService

nestjs http retry
by codesnips 3 tabs
go
package export

import (
	"encoding/csv"
	"log"
	"net/http"

Streaming Large CSV Exports in Go Without Buffering the Whole File

go http csv
by codesnips 3 tabs
javascript
const { EventEmitter } = require('events');

const HIGH_WATER_MARK = 1 << 20; // 1 MiB of buffered bytes per client

class SseHub extends EventEmitter {
  constructor() {

Broadcasting Events to Clients with Server-Sent Events on Node's http Module

nodejs sse server-sent-events
by codesnips 3 tabs
rust
#[derive(Debug, Clone, Copy)]
pub struct ByteRange {
    pub start: u64,
    pub end: u64, // inclusive
}

Serving HTTP Range Requests in Axum with Partial Content Responses

axum http range-requests
by codesnips 3 tabs