Skip to main content
gRPC

Unary RPC Call

RequestParseValidateEasy

What you will learn

  • Unary gRPC status codes differ from HTTP โ€” OK=0, INVALID_ARGUMENT=3, DEADLINE_EXCEEDED=4. Assert on code, not HTTP status
  • Test deadline propagation โ€” a 100ms deadline on client must abort the server-side work, not just the response read
  • Metadata (trailer) can carry structured errors โ€” richer than status alone, used in rpc retry-info patterns

Description

Make a simple unary (request-response) gRPC call to get a user by ID.

Test Scenario

// grpcurl example
grpcurl -plaintext \
  -d '{"id": "user-1"}' \
  localhost:50051 \
  practice.users.UserService/GetUser

// Expected response:
{
  "id": "user-1",
  "name": "John Doe",
  "email": "john@example.com",
  "role": "admin",
  "createdAt": "1703808000"
}

Testing Tips

  • โ€ขUnary is the simplest gRPC pattern (like REST GET)
  • โ€ขRequest and response are single messages
  • โ€ขUse grpcurl or grpc-client for testing
// 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-unary-call

2 frameworks available