Code Explainers

Code explainers tagged #etag

go
package api
 
import (
	"crypto/sha256"

ETag conditional requests in Gin

http-caching etag conditional-requests
Intermediate 6 steps
go
func UpdateArticle(store *ArticleStore) gin.HandlerFunc {
	return func(c *gin.Context) {
		id := c.Param("id")
 

Optimistic concurrency with If-Match in Gin

optimistic-locking http-preconditions etag
Intermediate 9 steps
javascript
const express = require('express');
const crypto = require('crypto');
const router = express.Router();
 

Optimistic locking with ETags in Express

optimistic-locking etag conditional-requests
Intermediate 7 steps
php
<?php
 
namespace App\Http\Controllers;
 

Serving cached translations from a Laravel controller

http-caching etag localization
Intermediate 8 steps
javascript
import { NextResponse } from 'next/server';
import { readFile, stat } from 'node:fs/promises';
import { join, extname, normalize } from 'node:path';
import { createHash } from 'node:crypto';

Serving private assets from a Next.js route

path-traversal http-caching etag
Intermediate 6 steps
typescript
import {
  Controller,
  Get,
  Param,

HTTP conditional caching in a NestJS controller

http-caching etag conditional-requests
Intermediate 7 steps
java
@Configuration
public class WebConfig {
 
    @Bean

HTTP caching with ETags in Spring

http-caching etag servlet-filters
Intermediate 6 steps
rust
use axum::body::Bytes;
use axum::http::{header, HeaderValue, StatusCode};
use axum::response::{IntoResponse, Response};
use serde::Serialize;

Custom Axum responses with per-user ETags

etag trait-implementation generics
Intermediate 7 steps
python
from pathlib import Path
 
from django.contrib.auth.decorators import login_required
from django.http import FileResponse, Http404, HttpResponseForbidden

Serving files with access checks in Django

authorization http-caching file-serving
Intermediate 7 steps
python
import hashlib
import json
from fastapi import APIRouter, Request, Response, Depends, HTTPException, status
 

HTTP ETag caching in a FastAPI route

http-caching etag conditional-requests
Intermediate 9 steps
javascript
const crypto = require('crypto');
 
function inMemoryCache({ maxAge = 60_000, maxEntries = 500 } = {}) {
  const store = new Map();

Building an in-memory cache middleware in Express

caching middleware etag
Advanced 10 steps
python
import hashlib
import os
from datetime import timedelta
 

Serving cacheable static assets in Flask

http-caching etag conditional-requests
Intermediate 8 steps
php
<?php
 
namespace App\Http\Middleware;
 

ETag caching and gzip in Laravel middleware

middleware http-caching etag
Intermediate 8 steps
go
func GetArticle(c *gin.Context) {
	id := c.Param("id")
 
	article, err := articleRepo.FindByID(c.Request.Context(), id)

Conditional GET with ETags in Gin

http-caching etag conditional-requests
Intermediate 7 steps
rust
use axum::{
    extract::{Path, State},
    http::{header, HeaderMap, StatusCode},
    response::{IntoResponse, Response},

Optimistic concurrency with ETags in Axum

optimistic-concurrency etag http-headers
Intermediate 8 steps