Code Explainers

Code explainers tagged #http

go
func UploadChunk(c *gin.Context) {
	uploadID := c.Param("uploadID")
	if !validUploadID.MatchString(uploadID) {
		c.JSON(http.StatusBadRequest, gin.H{"error": "invalid upload id"})

Resumable chunked uploads in Gin

file-upload content-range streaming
Advanced 9 steps
ruby
require "timeout"
require "net/http"
 
class RemoteInventoryClient

Bounding a slow HTTP call with Timeout in Ruby

timeout error-handling http
Intermediate 6 steps
java
public final class MultipartParser {
 
    public record FilePart(String name, String filename, String contentType, byte[] content) {}
 

Parsing multipart form data by hand in Java

parsing byte-arrays http
Advanced 8 steps
ruby
require "net/http"
require "json"
require "uri"
require "base64"

Paginating an HTTP API with a Ruby enumerator

pagination http enumerator
Intermediate 7 steps
rust
use axum::{
    body::Body,
    http::{Method, StatusCode, Uri},
    response::{IntoResponse, Response},

Nesting routers and JSON fallbacks in Axum

routing http json-responses
Intermediate 7 steps
go
package middleware
 
import (
	"errors"

Capping request body size in Gin

middleware request limits error handling
Intermediate 5 steps
ruby
require "net/http"
require "json"
 
class UrlFetcher

A thread-pool URL fetcher in Ruby

concurrency thread-pool queues
Intermediate 8 steps
go
package proxy
 
import (
	"log"

Building a hardened Go reverse proxy

reverse-proxy http timeouts
Intermediate 7 steps
go
package auth
 
import (
	"net/http"

Setting and reading secure session cookies in Go

cookies session-management security
Intermediate 6 steps
php
<?php
 
function fetchAll(array $urls, int $concurrency = 10, int $timeout = 15): array
{

Bounded-concurrency HTTP fetching with curl_multi

concurrency http curl
Advanced 8 steps
typescript
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import {
  Observable,

A city autocomplete service in Angular

rxjs observables debouncing
Intermediate 7 steps
go
package handlers
 
import (
	"encoding/json"

Hardening JSON decoding in Go HTTP handlers

json error-handling http
Intermediate 8 steps
go
package api
 
import (
	"encoding/json"

Building reusable JSON helpers in Go HTTP handlers

http json error-handling
Intermediate 9 steps
rust
use axum::{
    routing::get,
    Json, Router,
};

Response compression in Axum with tower-http

middleware compression http
Intermediate 6 steps
typescript
import { z, type ZodType } from "zod";
 
export class HttpError extends Error {
  constructor(

A type-safe fetch wrapper with Zod

generics runtime-validation error-handling
Intermediate 8 steps
java
@WebMvcTest(OrderController.class)
class OrderControllerTest {
 
    @Autowired

Slicing the web layer with @WebMvcTest in Spring

testing mocking web-layer
Intermediate 9 steps
go
package main
 
import (
	"html/template"

Auto-escaping HTML with Go templates

templating xss auto-escaping
Intermediate 6 steps
java
@Aspect
@Component
public class IdempotencyAspect {
 

How an idempotency aspect works in Spring

aop idempotency caching
Advanced 9 steps