RestClient is a synchronous fluent HTTP client. Use it in
a trusted service and expose your own authenticated application route to
frontends.
Prerequisites
Before you begin, prepare:- a trusted server runtime and application authentication boundary;
- a disposable personal workspace Praxa key with only the tutorial’s required scopes;
- synthetic input plus a persisted application request ID for replay tests;
- a fake upstream for unit tests and a non-production environment for canaries;
- an acceptance assertion that proves the Spring boundary admits one task with typed readback and a fake-client regression test.
1. Configure the client
src/main/java/example/PraxaClient.java
application.yml committed to source control.
2. Add an application controller
Your controller should authenticate the application principal, validate a bounded request DTO, deriveuserId, and invoke submitTask. It should never
accept a Praxa key, tenant, owner, or scope from the request.
Map upstream failures to customer-safe errors:
error.getResponseBodyAsString() to the browser unless a
reviewed redactor has projected it.
3. Test the outbound contract
UseMockRestServiceServer with the RestClient.Builder and assert:
- exact
/v1/executePOST; - bearer and idempotency headers;
- stable key for the same principal/request pair;
- different key for a different principal;
- no upstream call for invalid input;
- safe mapping for
401,403,409, and429; - no authorization value in controller responses or logs.
4. Verify live behavior
Use a disposable personal key. Submit one task, poll the returned run through a separate server-ownedGET /v1/runs/{id} client, verify terminal state,
replay the exact request, and revoke the key.
Troubleshooting
Best practices
- Reuse the thread-safe
RestClient. - Configure connect and read timeouts on the underlying request factory.
- Keep authentication and tenant derivation in the controller/service boundary.
- Use records or DTOs instead of unbounded maps in production.
- Preserve key/body digests for reconciliation.
- Prefer
RestClientover deprecatedRestTemplateon current Spring.
Spring REST clients
Review current
RestClient, WebClient, and HTTP service client guidance in
the official Spring Framework reference.Optimize for production
- Reuse one configured HTTP or SDK client per process and bound concurrent upstream work.
- Prefer durable admission plus asynchronous readback over holding application requests open.
- Cache only non-sensitive, tenant-scoped reads within their documented freshness window.
- Measure p50/p95 latency, admission-to-terminal time, retries, conflicts, and connection reuse before tuning.
Cleanup and next steps
- Revoke the disposable Praxa key and require a later request to fail.
- Remove synthetic application records and any temporary environment files.
- Cancel or archive unresolved test runs according to the application policy.
- Retain only redacted request, run, and verification identifiers needed for the test record.