Real World Example

A Payment API Request in Production

At a payment gateway like Razorpay, a "create payment" request passes through many layers. Mapped to NestJS:

StageWhat it does for POST /v1/payments
MiddlewareAssign x-request-id, log the request, parse raw body for signature checks
Guard 1: ApiKeyGuardCheck the merchant's API key and secret
Guard 2: ThrottlerGuardMax 100 requests per second per merchant
Interceptor: IdempotencyInterceptorSame Idempotency-Key twice? Return the first response
Pipe: ValidationPipeAmount is an integer in paise, currency is INR
Handler + servicesCreate the payment, call the bank/UPI switch
Interceptor (after)Wrap response, record latency metric
FilterBank timeout becomes 502 {"error":{"code":"GATEWAY_ERROR"}}

Example

curl -i -X POST https://api.shopease.in/v1/payments \
  -H "Authorization: Bearer sk_live_xxx" -H "Idempotency-Key: 7f1c-22" \
  -H "Content-Type: application/json" -d '{"orderId":"ORD-7781","amount":129900,"currency":"INR","method":"upi"}'

Example output

HTTP/1.1 201 Created
X-Request-Id: 0b9a5c1e
X-Response-Time: 182ms

{"data":{"paymentId":"pay_N8kq2","status":"created","amount":129900,"currency":"INR"}}