Code Explainers

Code explainers tagged #dependency-injection

python
import time
from dataclasses import dataclass, field
 
from fastapi import Depends, FastAPI, HTTPException, Request, status

Token-bucket rate limiting in FastAPI

rate-limiting token-bucket dependency-injection
Advanced 10 steps
java
@Service
public class GitHubClient {
 
    private final WebClient webClient;

Calling the GitHub API with Spring WebClient

reactive http-client dependency-injection
Intermediate 7 steps
typescript
import { Injectable, Logger } from '@nestjs/common';
import { Cron, CronExpression } from '@nestjs/schedule';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository, LessThan } from 'typeorm';

Scheduled session cleanup in NestJS

cron-scheduling background-jobs repository-pattern
Intermediate 7 steps
php
<?php
 
namespace App\Providers;
 

Binding a payment gateway in Laravel

dependency-injection service-container interface-binding
Intermediate 7 steps
java
@RestController
@RequestMapping("/webhooks/stripe")
public class StripeWebhookController {
 

How a Stripe webhook controller works in Spring

webhooks signature-verification event-handling
Intermediate 7 steps
typescript
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, shareReplay } from 'rxjs';
 

Caching HTTP config in an Angular service

caching observables dependency-injection
Intermediate 6 steps
java
@RestController
@RequestMapping("/api/products")
public class ProductController {
 

How a paginated REST controller works in Spring

pagination dto-mapping dependency-injection
Intermediate 8 steps
python
from fastapi import APIRouter, Depends, Query
from pydantic import BaseModel
from sqlalchemy import func, select
from sqlalchemy.ext.asyncio import AsyncSession

How a paginated list endpoint works in FastAPI

pagination dependency-injection async-orm
Intermediate 8 steps
typescript
import { IsEmail, IsEnum, IsInt, IsOptional, IsString, Length, Max, Min } from 'class-validator';
import { Type } from 'class-transformer';
import { Body, Controller, Post } from '@nestjs/common';
 

How DTO validation works in NestJS

validation data-transfer-objects decorators
Intermediate 8 steps
go
package handlers
 
import (
	"net/http"

Rendering HTML pages with Gin handlers

http-handlers templating error-handling
Beginner 8 steps