| name | servicestack-typed-clients |
| description | Leverages typed ServiceStack clients and DTO reuse across boundaries. |
ServiceStack Typed Clients
Typed clients provide a type-safe way to consume ServiceStack APIs without manual URL construction or code generation.
Supported Clients
ServiceStack provides clients for many languages:
- C#:
JsonServiceClient, JsonHttpClient.
- TypeScript:
JsonServiceClient.
- Java/Kotlin, Swift, Dart, etc.
Basic Usage (C#)
var client = new JsonServiceClient(BaseUrl);
var response = await client.GetAsync(new GetCustomer { Id = 1 });
Key Benefits
- No Code Gen: C# clients share the same DTO assembly (
ServiceModel) as the server.
- Type Safety: Compile-time checking of request and response types.
- Automatic Routing: The client knows the correct URL and Verb from the DTO's attributes (
[Route], IReturn<T>).
Generic Error Handling
Clients automatically handle WebServiceException and provide access to the ResponseStatus for structured error reporting.
Best Practices
- Reuse DTOs: Always use the same DTO assembly in your .NET clients.
- Async First: Use the
*Async methods for better performance and scalability.
- Centralized Configuration: Configure the client (base URL, default headers, credentials) in a central location.
- Error Triage: Use the typed
ResponseStatus to provide meaningful feedback to users.