Code Explainers

Code explainers tagged #content-negotiation

java
@GetMapping("/files/{id}")
public ResponseEntity<StreamingResponseBody> download(
        @PathVariable String id,
        @RequestHeader(value = HttpHeaders.RANGE, required = false) String rangeHeader) throws IOException {

HTTP range requests in Spring

http-range streaming file-io
Advanced 10 steps
python
from flask import Blueprint, render_template, jsonify, request, abort
 
from .models import Article
 

Content negotiation in a Flask Blueprint

content-negotiation http-headers routing
Intermediate 7 steps
go
package middleware
 
import (
	"net/http"

Localized validation errors in Gin

middleware internationalization validation
Intermediate 8 steps
javascript
import { NextResponse } from 'next/server';
 
const locales = ['en', 'fr', 'de', 'es'];
const defaultLocale = 'en';

Locale routing with Next.js middleware

middleware i18n content-negotiation
Intermediate 10 steps
rust
use axum::{
    extract::FromRequestParts,
    http::{request::Parts, StatusCode, header::ACCEPT_LANGUAGE},
};

A locale extractor for Axum handlers

content-negotiation http-headers custom-extractor
Intermediate 7 steps
go
package handlers
 
import (
	"net/http"

Header-driven API versioning in Gin

api-versioning header-binding closures
Intermediate 6 steps
rust
use axum::{
    async_trait,
    body::Bytes,
    extract::FromRequest,

A strict JSON extractor in Axum

extractors traits content-negotiation
Advanced 7 steps
java
@RestController
@RequestMapping("/api/orders")
public class OrderController {
 

Content-negotiated API versioning in Spring

api-versioning content-negotiation rest
Intermediate 7 steps
javascript
const express = require('express');
const router = express.Router();
 
router.get('/articles/:slug', async (req, res, next) => {

Content negotiation with res.format in Express

content-negotiation routing error-handling
Intermediate 9 steps
go
package handlers
 
import (
	"net/http"

Content negotiation in Gin handlers

content-negotiation struct-tags rest-api
Intermediate 4 steps
rust
use axum::{
    extract::Path,
    http::{header::ACCEPT, HeaderMap, StatusCode},
    response::{Html, IntoResponse, Json, Response},

Content negotiation in an Axum handler

content-negotiation http-headers serialization
Intermediate 8 steps
php
<?php
 
namespace App\Http\Middleware;
 

Enforcing a JSON Accept header in Laravel

middleware content-negotiation http-headers
Beginner 5 steps