When designing a RESTful Web Service should the API be designed to work ID for Strings for values passed back and forth between the server?
Here's an example: Let's say I have an Employee resource, which has a status and gender attributes. In the database Status and Gender and separate tables and thus separate Domain object, each with its own identifier.
Let's say the client request /employee/1. There server might return something like these....
Case 1:
{
"id": 1,
"firstName": "Jane",
"lastName": "Doe",
"active": true,
"gender": {
"id": 1,
"gender": "FEMALE"
},
"status": {
"id": 3,
"status": "FULL_TIME"
}
}
Case 2:
{
"id": 1,
"firstName": "Jane",
"lastName": "Doe",
"active": true,
"gender": "FEMALE",
"status": "FULL_TIME"
}
Case 3:
{
"id": 1,
"firstName": "Jane",
"lastName": "Doe",
"active": true,
"genderId": 1,
"statusId": 3
}
Case 3 seems to make the least sense as the client has no idea what genderId 1 is unless it turns around and makes another call to the server to get that data.
However now let's say the client is updating the user through:
PUT /employee/1
Should the request Payload use the ids or a string? Either way, the back-end has to look them up to make sure they are valid, but it is nicer to work with IDs over Strings.