interceptor

typescript
import { Injectable } from '@nestjs/common';

export interface RateLimitResult {
  allowed: boolean;
  remaining: number;
  limit: number;

Sliding-Window Webhook Rate Limiting with a NestJS Interceptor and In-Memory Counter

typescript nestjs rate-limiting
by codesnips 3 tabs
java
package com.example.ratelimit;

public class TokenBucket {

    private final long capacity;
    private final long refillTokens;

Per-Client Token Bucket Rate Limiting with a Spring Boot HandlerInterceptor

spring-boot rate-limiting token-bucket
by codesnips 4 tabs
java
package com.example.github;

import java.util.List;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Path;

Declarative Typed HTTP Client With Retrofit and an OkHttp Auth Interceptor

retrofit okhttp http-client
by codesnips 3 tabs
java
package com.example.http;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;

Attaching Bearer Tokens to Spring RestClient Calls with a ClientHttpRequestInterceptor

spring-boot restclient interceptor
by codesnips 3 tabs
typescript
import { Exclude, Expose } from 'class-transformer';

export class User {
  id: string;

  firstName: string;

Hide Sensitive Fields in NestJS Responses with class-transformer and ClassSerializerInterceptor

nestjs class-transformer serialization
by codesnips 3 tabs
typescript
import { AxiosError } from 'axios';

export const RETRY_CONFIG = {
  maxRetries: 4,
  baseDelayMs: 200,
  maxDelayMs: 5_000,

Exponential-Backoff Retry Interceptor Around NestJS HttpService

nestjs http retry
by codesnips 3 tabs
typescript
import { Injectable } from '@nestjs/common';

type Completed = { status: 'completed'; statusCode: number; body: unknown; expiresAt: number };
type InFlight = { status: 'in-flight'; startedAt: number };
type Record = Completed | InFlight;

Idempotency-Key Interceptor in NestJS to Debounce Duplicate Form Submissions

nestjs idempotency interceptor
by codesnips 4 tabs
java
@Entity
@Table(name = "invoices")
@FilterDef(
    name = "tenantFilter",
    parameters = @ParamDef(name = "tenantId", type = String.class)
)

Per-Tenant Row Filtering with Hibernate @Filter Enabled Per Request

hibernate jpa multi-tenancy
by codesnips 4 tabs