Given the following REST endpoints:
(GET, POST) /api/v2/employer
(GET) /api/v2/employer/{id}
(GET, POST) /api/v2/employer/{id}/employees
Should a consumer of this API have the ability to POST a new employer resource that includes a list of employees? For example:
POST: /api/v2/employer
{
employerName: "Bob's Plumbing",
headquarters: "Des Moines, IA, US",
industry: "plumbing",
employees: [
{ firstName: "Bob", lastName: "Jones", dob: "1982-05-16" },
{ firstName: "Philip", lastName: "Jones", dob: "2001-03-12" },
{ firstName: "John", lastName: "Smith", dob: "1991-02-19" }
]
}
Or, should the consumer be required to break this into multiple calls?
POST: /api/v2/employer
{
employerName: "Bob's Plumbing",
headquarters: "Des Moines, IA, US",
industry: "plumbing",
}
// ... the ID of the new employer is returned (for example, "5") ...
POST: /api/v2/employer/5/employees
{ firstName: "Bob", lastName: "Jones", dob: "1982-05-16" }
POST: /api/v2/employer/5/employees
{ firstName: "Philip", lastName: "Jones", dob: "2001-03-12" }
POST: /api/v2/employer/5/employees
{ firstName: "John", lastName: "Smith", dob: "1991-02-19" }