http

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
'use strict';

const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

function backoffDelay(attempt, baseMs, maxDelayMs) {
  const exponential = baseMs * 2 ** attempt;

Retry Failed Async Operations With Exponential Backoff and Jitter in Node.js

nodejs retry backoff
by codesnips 2 tabs
go
package middleware

import (
  "net/http"

  "golang.org/x/time/rate"

Inbound rate limiting middleware with token bucket

go http rate-limit
by Leah Thompson 1 tab
go
package health

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

Readiness and liveness probes with dependency checks

go http kubernetes
by Leah Thompson 1 tab
ruby
class SubscriptionsController < ApplicationController
  before_action :set_subscription, only: %i[show destroy]

  def new
    @subscription = Subscription.new
  end

Use 303 See Other after POST in Turbo flows

rails hotwire turbo
by codesnips 3 tabs
rust
use serde::{Deserialize, Deserializer};
use time::OffsetDateTime;

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UserProfile {

Deserializing Optional and Renamed JSON API Fields with Serde in Rust

rust serde serde-json
by codesnips 2 tabs
javascript
class TokenBucket {
  constructor(capacity, refillRatePerSec) {
    this.capacity = capacity;
    this.refillRate = refillRatePerSec;
    this.tokens = capacity;
    this.lastRefill = Date.now();

Token Bucket Rate Limiter as Express Middleware

express rate-limiting token-bucket
by codesnips 3 tabs
typescript
import { cookies } from "next/headers";
import { jwtVerify } from "jose";

export interface Session {
  userId: string;
  role: "user" | "admin";

Next.js Route Handler with auth guard

nextjs route-handlers authentication
by codesnips 3 tabs
ruby
# Basic middleware structure
class RequestTimerMiddleware
  def initialize(app)
    @app = app
  end

Rack middleware for request/response processing

ruby rails rack
by Sarah Mitchell 2 tabs
java
package com.example.api.error;

import com.fasterxml.jackson.annotation.JsonInclude;

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

Structured Error Responses with @RestControllerAdvice in Spring Boot

spring-boot rest-api exception-handling
by codesnips 3 tabs
typescript
import { SetMetadata } from '@nestjs/common';

export const CACHEABLE_KEY = 'cacheable:options';

export type VaryDimension = 'user' | 'tenant' | 'query';

Per-Route Response Caching in NestJS with a Custom CacheInterceptor and Cache Key Builder

nestjs caching interceptors
by codesnips 4 tabs
go
package api

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

Consistent JSON responses (content-type + error envelopes)

go http json
by Leah Thompson 1 tab