connexion20000
connexion20000

Reputation: 335

REST API design- additional information about items in collection

I have one collection at endpoint /servers that returns information about all servers:

{
    uid: "5t7yu8i9io0op",
    service_name: "Service Test",
    dc: "dc1",
    sync: true
}

it is simple endpoint that requires to only hit db from backend. But servers have a lot of additional information about them, f.e. heath status (more work for backend). So if I want to check health of one server, I hit endpoint /servers/:uid/health and I get:

{
    overall_status: "HEALTH_OK",
    warnings: [],
    errors: []
}

But now my problem is, that I would like to get health checks from all servers, so how should such API look like? Should it be /servers/health, /healthchecks ? Or maybe it should be embeddable in primary collection like: /servers?health=true ?

Upvotes: 0

Views: 45

Answers (1)

Amal Gupta
Amal Gupta

Reputation: 452

Assumption: The service request may have idea about the server names, or ids, or host names. For the sake if brevity, let us call it serverId;

Then you can design your api like

Suggested Solution To Your Question

/servers/health/{serverId}

in place of the serverId pass a text like 'ALL' and you know how the api will respond.

For most of the interacting endpoints, creation of this request is straightforward, and moreover it should, in ideal cases, return the response in less than 1 second.

Additional Use Case

This endpoint leads to a potential use case of one more scenario, What if a health check is needed on a subset of the servers identified?

Use a text 'SUBSET' in the endpoint request for {serverId}, and pass the subset of serverID in the request body.

Needless to say, the expected approach to fetch the health will include spawning different threads to fetch the health of each server, and consolidating the results in a single response.

Upvotes: 1

Related Questions