HttpClient in your trusted backend and keep the Praxa key out of WebAssembly,
desktop, and mobile bundles.
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 ASP.NET boundary admits and reconciles one task through the shared HttpClient.
1. Register the client
Program.cs
2. Implement the typed client
PraxaClient.cs
userId; the untrusted request body does
not. Store the key in a protected configuration provider such as your cloud
secret manager or environment, not in appsettings.json committed to Git.
3. Expose a bounded endpoint
In ASP.NET Core, authenticate and validate before invoking the client:Cache-Control: no-store and your application rate limit. Map upstream
errors to a safe problem document rather than exposing the response body.
4. Test with a fake handler
Create a customHttpMessageHandler or use your preferred HTTP test library.
Assert:
- invalid input makes no outbound request;
- authorization and idempotency headers are correct;
- the same user/request pair produces the same key;
- cancellation reaches
SendAsync; 401,403,409, and429map to distinct safe errors;- no secret appears in logs or response JSON.
5. Verify live behavior
Use a disposable least-privilege key, submit one task, read it to terminal, replay the exact request, then revoke the key. AnAccepted response proves
admission only.
Troubleshooting
Best practices
- Use
IHttpClientFactoryand explicit timeouts. - Forward cancellation tokens.
- Keep typed authority outside client-controlled DTOs.
- Bound JSON input and response size.
- Record safe status/problem metadata only.
- Test exact retry and cross-tenant refusal before production.
HttpClient guidelines
Review connection pooling, lifetime, DNS, retry, and client-factory guidance
in the official .NET documentation.
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.