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?
{
"id"—1,
"status": {
"id" : 2, // Which one do you prefer?
"name": "In Progress" // Which one do you prefer?
}
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="/>
© 2024 OneMinuteCode. All rights reserved.