I'm currently working on an API for an education app. There's a teacher resource and each teacher has a list of subjects that they teach. Currently, the GET teacher endpoint looks like this:
{
"first_name" : "Mister"
"last_name" : "Teacher"
"subjects" : [
{
"name" : "English",
"icons" : "/english-icon.png"
"id" : 1
},
{
"name" : "Math",
"icons" : "/math-icon.png"
"id" : 2
}
]
}
However, to me it doesn't make sense send the entire subject object when creating and updating the subjects, so the POST and PUT student endpoints accept parameters in the following form:
{
"first_name" : "Mister"
"last_name" : "Teacher"
"subject_ids": [1,2]
}
The inconsistency seems ugly, and it forces the client application to modify the format of an object before sending it to the server. Is there a more elegant solution?