Skip to main content
gRPC

Interceptors (Middleware)

MockRequestValidateMedium

What you will learn

  • Server-side interceptors run in registration order โ€” auth โ†’ logging โ†’ tracing. Order change = behaviour change
  • Client-side interceptors wrap outgoing calls โ€” add metadata, tracing, retry logic in one place
  • Test interceptor failure: if auth interceptor throws, subsequent interceptors don't run. Verify cleanup (span end, logs flushed)

Description

Understand how interceptors add logging, auth, and metrics to gRPC calls.

Test Scenario

// Example: logging interceptor output
[gRPC] START /practice.users.UserService/GetUser
[gRPC] REQ: {"id": "user-1"}
[gRPC] RES: {"id": "user-1", "name": "John"}
[gRPC] END: OK (15ms)

// Example: auth interceptor
[gRPC] AUTH: Checking token...
[gRPC] AUTH: Valid user: admin

Testing Tips

  • โ€ขInterceptors wrap RPC calls
  • โ€ขCan modify request/response
  • โ€ขCommon uses: logging, auth, metrics, retry
// Playwright API Testing - gRPC (via REST gateway)
import { test, expect } from '@playwright/test';
test('gRPC unary call via gateway', async ({ request }) => {
const response = await request.post('/api/grpc/UserService/GetUser', {
data: { id: '1' }
});
expect(response.ok()).toBeTruthy();
const data = await response.json();
expect(data.user).toBeDefined();
});

Challenge ID: grpc-interceptors

2 frameworks available