net/http client from a trusted backend. Reuse the client,
set a timeout, and keep the Praxa key out of browser or mobile code.
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 Go handler reuses its client, respects context cancellation, and reconciles one durable run.
1. Implement the client
praxa/client.go
2. Add the application handler
Your Gin, Chi, Echo, Fiber, or standard-library handler should authenticate the caller, bound the JSON body, deriveuserID, and call SubmitTask. Return a
safe projection and Cache-Control: no-store.
Never accept a Praxa key, tenant, owner, or upstream scope from the caller.
3. Test with httptest
Create an httptest.Server, point Client.Origin to its URL, and assert:
- the handler receives exactly one POST;
- authorization never appears in application output;
- repeated user/request pairs produce the same key;
- changed users produce different keys;
- invalid input makes no request;
- non-2xx responses remain errors;
- context cancellation stops the local HTTP request.
4. Verify end to end
Use a disposable key withexecute:write and runs:read. Submit a task, read
the run to terminal, replay the exact request, then revoke the key.
Troubleshooting
Best practices
- Reuse
http.Clientand its transport. - Pass request contexts through every layer.
- Use typed request/response structures in production.
- Bound body size before decoding.
- Rate-limit per authenticated principal.
- Keep idempotency records until the operation is reconciled.
Go REST service tutorial
Review the official Go guide for structuring and testing REST handlers.
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.