http

rust
use axum::{routing::get, Router, Json};
use serde::Serialize;

#[derive(Serialize)]
struct Response {
    message: String,

axum for type-safe async HTTP servers

rust async axum
by Marcus Chen 1 tab
go
package middleware

import (
  "net/http"

  "go.uber.org/zap"

Panic recovery middleware for HTTP servers

go http middleware
by Leah Thompson 1 tab
python
from sqlalchemy import select

from .models import Order, db


def stream_orders(batch_size=1000):

Stream a Large CSV Export in Flask With a Generator Response

flask streaming csv
by codesnips 3 tabs
go
package middleware

import (
  "log"
  "net/http"
  "runtime/debug"

Panic recovery middleware that fails closed and logs context

go http middleware
by Leah Thompson 1 tab
typescript
export type ErrorCode =
  | 'VALIDATION'
  | 'UNAUTHENTICATED'
  | 'FORBIDDEN'
  | 'NOT_FOUND'
  | 'CONFLICT'

API error shape that frontend can rely on

typescript express react
by codesnips 4 tabs
ruby
class Problem
  DEFAULT_TYPE = "https://api.example.com/problems/about:blank".freeze

  attr_reader :type, :title, :status, :detail, :instance, :extensions

  def initialize(status:, title:, detail: nil, type: nil, instance: nil, extensions: {})

API Error Handling with Problem Details (RFC7807-ish)

rails api error-handling
by codesnips 3 tabs
go
package web

import (
  "bytes"
  "html/template"
  "net/http"

Template rendering with html/template and strict escaping

go templates http
by Leah Thompson 1 tab
javascript
const jwt = require('jsonwebtoken');

const SECRET = process.env.JWT_SECRET;
const ALGORITHM = 'HS256';
const ACCESS_TTL = '15m';

JWT Authentication Middleware in Express That Populates req.user

express jwt authentication
by codesnips 3 tabs
go
package feed

import "time"

type Event struct {
	ID        string    `json:"id"`

Stream and Decode Newline-Delimited JSON (NDJSON) from an HTTP Response Body in Go

go ndjson streaming
by codesnips 3 tabs
ruby
class OrderPresenter < SimpleDelegator
  attr_reader :current_user

  def initialize(order, current_user:)
    super(order)
    @current_user = current_user

Presenter + fast_jsonapi Serializer for Clean JSON:API Responses in Rails

rails json-api serialization
by codesnips 3 tabs
rust
use reqwest;
use serde::Deserialize;

#[derive(Deserialize, Debug)]
struct Post {
    id: u32,

reqwest for async HTTP client with connection pooling

rust http async
by Marcus Chen 1 tab
javascript
const { z } = require('zod');

const signupSchema = z
  .object({
    email: z
      .string()

Reusable Zod Schema Validation Middleware for Express Signup Routes

express zod validation
by codesnips 3 tabs