gov-uk-rs-sdk
Rust workspace for Companies House and related GOV.UK HTTP APIs.
gov-uk-rs-sdk(this repo’s rootsrc/) — published umbrella crate with aharnessmodule (ApiResponse,ApiError,ApiRequest,into_api_result), prelude, and examples.crates/gov-uk-sdk-core— sharedreqwestclient, auth, rate limiting, negotiation, errors.crates/gov-uk-ch-*— thin product crates (Public Data, Document stub, …).
Harness (root src/harness)
| Type | Role |
|---|---|
ApiResponse<T> |
Success envelope: body + Content-Type / CH-Expiry-Date (NegotiatedMeta) |
ApiError |
Alias of SdkError |
ApiRequest |
Chaining wrapper around SdkRequest + send_json_api / send_empty_api |
into_api_result |
Maps SdkResult<NegotiatedResponse<T>> → ApiResult<ApiResponse<T>> |
Low-level behaviour stays in gov-uk-sdk-core; the harness only composes types for one import path.
Crates
| Path | Package | Role |
|---|---|---|
src/ (root [package]) |
gov-uk-rs-sdk |
Umbrella + harness + prelude |
crates/gov-uk-sdk-core |
gov-uk-sdk-core |
HTTP stack, auth, limits, negotiation |
crates/gov-uk-ch-public-data |
gov-uk-ch-public-data |
Public Data API |
crates/gov-uk-ch-document |
gov-uk-ch-document |
Document API (stub) |
Usage
From crates.io (after publish):
[]
= { = "0.1", = ["ch-public-data"] }
= { = "1", = ["rt-multi-thread", "macros"] }
Local path (workspace root):
= { = ".", = ["ch-public-data"] }
Configuration (.env)
- Copy
.env.exampleto.envin the repo root. - Set
COMPANIES_HOUSE_API_KEY(from the Developer Hub). .envis gitignored — never commit real keys. The committed.env.exampledocuments variables only.
Examples and the ignored integration test call dotenvy::dotenv() so a local .env is picked up automatically when you run from the workspace root.
Do not commit API keys. Prefer .env locally, CI secrets, or a vault in production.
use ;
use *;
use env;
async
Features (gov-uk-rs-sdk)
ch-public-data(default) — Public Data API.ch-document— Document API stub.full— all product crates.
Thin integration (core + one product only)
= "0.1"
= "0.1"
Examples
Tests
Live Companies House call (ignored by default):
See CHANGELOG.md for release notes.
Publishing to crates.io
Publish in dependency order (all from this repo root):
cargo publish -p gov-uk-sdk-corecargo publish -p gov-uk-ch-documentcargo publish -p gov-uk-ch-public-datacargo publish -p gov-uk-rs-sdk
Why step 2 is required: gov-uk-ch-document is an optional feature dependency on the umbrella, but Cargo still resolves every [dependencies] entry against crates.io when you package gov-uk-rs-sdk. If gov-uk-ch-document is not published yet, cargo publish -p gov-uk-rs-sdk fails with no matching package named gov-uk-ch-document. Publish the leaf crates (2 and 3) before the umbrella (4).
Workspace [workspace.dependencies] already sets compatible version + path for internal crates. After gov-uk-sdk-core is on crates.io, downstream publishes resolve it by version.
Dry run (the umbrella dry-run only succeeds after steps 1–3 have been published, or use --dry-run per crate after each real publish):
Companies House notes
- Auth: HTTP Basic — username = API key, password empty. OAuth uses
Auth::Bearer { token }. - Rate limits: Up to 600 requests / 5 minutes per application; 429 when exceeded. Client-side throttle is on by default —
.enable_companies_house_rate_limit(false)to disable. Avoid tight retry loops; respectRetry-After. Attempts to bypass limits can result in bans. - Versioning: Per-resource
Accept/Content-TypeMIME +version=; 406 / 410 /CH-Expiry-Date— see core types and developer docs.
Adding a new API product crate
- Add
crates/gov-uk-ch-<name>/depending only ongov-uk-sdk-core. - Register it in root
[workspace.members]and[workspace.dependencies]withversion+path. - Add optional dependency + feature on root
gov-uk-rs-sdkand extendprelude.
License
MIT — see LICENSE.