Code Explainers

Code explainers tagged #routing

go
package handlers
 
import (
	"net/http"

Serving embedded static meta files in Gin

embedding static assets http caching
Intermediate 6 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
javascript
import { useEffect, useRef } from "react";
import { useLocation } from "react-router-dom";
 
export function RouteFocus({ title, children }) {

Managing focus on route change in React

accessibility focus-management routing
Intermediate 6 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 admin
 
import (
	"net/http"

Building a protected admin area in Gin

routing middleware authentication
Intermediate 6 steps
rust
use axum::{
    extract::Path,
    http::StatusCode,
    routing::{get, post},

Building a REST resource in Axum

rest-api routing serialization
Intermediate 9 steps
javascript
import { NavLink, useLocation } from 'react-router-dom';
 
const NAV_ITEMS = [
  { to: '/', label: 'Dashboard', end: true },

Building an accessible Sidebar in React

routing accessibility declarative-ui
Intermediate 6 steps
rust
use axum::{
    body::Body,
    http::{header, HeaderValue, StatusCode, Uri},
    response::{IntoResponse, Response},

Serving embedded static files in Axum

static-assets embedding http-headers
Intermediate 7 steps
typescript
import { Controller, Get, Param, Query, Redirect, NotFoundException } from '@nestjs/common';
import { LinksService } from './links.service';
 
@Controller('links')

Handling HTTP redirects in NestJS

redirects routing decorators
Intermediate 7 steps
php
final class Route
{
    private string $regex;
    private array $paramNames = [];

Compiling route patterns into regex in PHP

routing regex parsing
Intermediate 8 steps
typescript
import { Controller, Get, Param, Post, Body, Version, VERSION_NEUTRAL } from '@nestjs/common';
import { UsersService } from './users.service';
import { CreateUserDto } from './dto/create-user.dto';
 

How API versioning works in NestJS

api-versioning routing dependency-injection
Intermediate 9 steps
python
from fastapi import APIRouter, FastAPI, HTTPException
from pydantic import BaseModel
 
 

Versioning a FastAPI API with mounted sub-apps

api-versioning response-models sub-applications
Intermediate 6 steps
javascript
import { lazy, Suspense } from "react";
import { Routes, Route, NavLink } from "react-router-dom";
import ErrorBoundary from "./components/ErrorBoundary";
import Spinner from "./components/Spinner";

Lazy-loaded routes in React

code-splitting lazy-loading routing
Intermediate 6 steps
python
from functools import wraps
from flask import Blueprint, session, request, redirect, url_for, flash, render_template
from werkzeug.security import check_password_hash
 

Session-based auth with a Flask Blueprint

authentication decorators sessions
Intermediate 9 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 api
 
func RegisterRoutes(r *gin.Engine, deps *Dependencies) {
	r.GET("/health", func(c *gin.Context) {

Layering route groups and middleware in Gin

routing middleware authentication
Intermediate 8 steps
python
from datetime import datetime
from fastapi import APIRouter, Depends, HTTPException, status
from pydantic import BaseModel, ConfigDict, EmailStr
from sqlalchemy.orm import Session

Building a users router in FastAPI

routing serialization dependency-injection
Intermediate 7 steps
typescript
import { Injectable } from '@angular/core';
import { PreloadingStrategy, Route, Routes, RouterModule } from '@angular/router';
import { NgModule } from '@angular/core';
import { Observable, of, timer } from 'rxjs';

A custom preloading strategy in Angular

lazy-loading preloading rxjs
Intermediate 7 steps