Is the master information contained in the WebAPI response body an ID or a value associated with the ID?

Asked 1 years ago, Updated 1 years ago, 360 views

When I put the master's data into the WebAPI response body, is it better to return the ID or the value associated with the ID?

For example, in the case of a WebAPI response body like GET/tasks/1 that retrieves a task, which should I return, status id or name?

Response Body Samples

{
 "id"—1,
 "status": {
  "id" : 2, // Which one do you prefer?
  "name": "In Progress" // Which one do you prefer?
}

status master table

webapi

2023-01-20 16:07

1 Answers

From the example provided, I imagined it was like a to-do list, but personally, I find it difficult to understand the format of returning id=numerical value (from the perspective of the user).

In the end, it may depend on the direction of the design, but one way is to refer to a similar API.
The Microsoft Graph API seems to return a state string as follows:

todoTask resource type-Microsoft Graph v1.0|Microsoft Learn

Alternatively, for simpler "completed" toggle, Remember The Milk has a field called completed.

Remember The Milk-Services/API/Tasks

<task id="815784" due="has_due_time="0"
        added="2015-05-08T13:52:26Z" completed="deleted=""
        priority="2" postponed="0" estimate="/>


2023-01-20 23:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.