API design recommendations
X-Road passes through any REST or SOAP service. However, a published service is used by many organisations for many years, so getting it right from the start is far cheaper than fixing it later.
Stability
- Do not change the service code or the subsystem code. They are written into every consumer's address.
- Put the version in the path:
/v1/…,/v2/…. Every incompatible change is a new version. - Compatible changes (adding a new field or a new path) do not change the version. State in your description that consumers must be written to ignore fields they do not recognise.
- Before you retire an old version, announce a deadline to your consumers. You can see who is calling from the Security Server's logs.
Description
- Write an OpenAPI 3 description and register the service with it. The description becomes the contract.
- For every field, state the type, unit, whether it is mandatory, and the possible values. Use ISO 8601 for dates (
2026-12-03,2026-12-03T09:30:00+08:00) and give monetary amounts with their currency. - Include example requests and responses in the description, using fictitious data.
Granularity of access rights
Access rights are granted per service, and further per path. Therefore:
- Expose data intended for different parties through different services or different paths. A single large path that "returns everything" makes it impossible to grant access rights at a fine granularity.
- Return the minimum information the consumer needs. "A loan decision needs income" is not a reason to return the entire personal file.
Recording who and why
The Security Server confirms "which system of which organisation made the call". It does not know "which employee, on what basis". If you return personal data:
- Make the
X-Road-UserIdandX-Road-Issueheaders mandatory, and return400if they are missing. - Store
X-Road-Client,X-Road-IdandX-Road-UserIdin your access log.
Error responses
- Use HTTP statuses for their meaning:
400bad request,404not found,409conflict,500an error on your side. - Give both a machine-readable code and a human-readable description in the body. Example:
json
{ "code": "CITIZEN_NOT_FOUND", "message": "No citizen with this register number was found." }- Do not expose internal error text, SQL or stack traces in the response.
- Consider whether distinguishing "not found" from "not authorised" would disclose information.
Performance
- Paginate every path that returns a list. Do not return unbounded lists.
- Respond faster than the timeout configured on the Security Server. For long-running operations, reply "request accepted" and let the result be queried separately.
- Make
POSTsafe to repeat so that it is not written twice: detect duplicates using the consumer'sX-Road-Idor a dedicated unique key.
Checklist before publishing
- The description matches the real responses.
- The service accepts requests only from the Security Server.
- Access rights have been granted with the narrowest scope.
- The access log is stored together with
X-Road-Id. - You have tested by calling from another subsystem, and confirmed that a subsystem without access receives
AccessDenied.