http

rust
use std::sync::Arc;
use std::time::Duration;

use futures::stream::{FuturesUnordered, StreamExt};
use reqwest::Client;
use tokio::sync::Semaphore;

Bounded Concurrent HTTP Fan-Out With FuturesUnordered and Semaphore in Rust

rust async tokio
by codesnips 3 tabs
rust
use axum::{Router, routing::get};
use tower::ServiceBuilder;
use tower_http::{trace::TraceLayer, timeout::TimeoutLayer};
use std::time::Duration;

async fn handler() -> &'static str {

Tower middleware for composable HTTP service layers

rust tower middleware
by Marcus Chen 1 tab
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
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
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
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
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