consider the following resources
-Year
-Classroom
-Students
I create a new resource with next URIs related to
PUT /years/{year Es: 2108}
PUT /classrooms/{classroom code Es: ls1sa, ls2sa, ls3sa...}
POST /students
A student for a specific year belong to the classroom and the next year, if he studies, will pass to the next classroom.
I'd like to create a new resource associations year-classroom-students using the following URI
/years/{yearCode}/classrooms/{classroomCode}/students/{studentsId}
Before save new resource I check for yearCode, classroomCode, and studentId.
Which HTTP status code should I send when one of the previous resource is missing?
Once the invalid values are sent in the URL, which is used to locate a resource in the server, in you could return
404
:On the other hand, if you want to send the parameters in the request payload, you could consider
422
to indicate that the request entity cannot be processed:For both situations, the response payload should contain details about the error. Have a look at the RFC 7807.