0
votes

I have 2 resources company and employees, where company can exist without employees, but not other way round.

To create company with employees, I have to fire 2 REST APIs,

POST /companies
POST /companies/:company_id/employees

Q1: Is it fine if I create employees and companies in single rest query to

POST /companies
{
  "company_name": "my company",
  "employees": [
     {"name": "Test name 1"},
     {"name": "Test name 2"}
  ]
}

Q2: If yes, is it mandatory that GET request to /companies should also return the same nested document?

I was planning something like this: Use above query to POST company data with employees

GET /companies - Will give me only company data
GET /companies?populate=employees - Will populate the nested resouces in this GET call
GET /companies/:company_id/employees - I still should be able to access employees in this manner
1

1 Answers

0
votes

How would you do it on a web site?

Q1: Is it fine if I create employees and companies in single rest query to

Yes, it is fine to create multiple resources in response to a single request.

Q2: If yes, is it mandatory that GET request to /companies should also return the same nested document?

No, it is not mandatory.