POST request with multiple components

Hello,

I’ve been reading up on the discussions about posting bulk data or a collection of entities on both the forum and the git repo and haven’t reached at any useful conclusion, therefore, I decided to write a question of my own here with a clear example and hopefully reach a conclusion about it.

My case is creating a reservation. The reservation in itself doesn’t hold much data, but is composed of other components such as reservation_flight, reservation_accommodation, reservation_passenger.

How does one go about creating such a reservation where all the subcomponents are new (not already existent like the example in the specs)?

Client side generated ids is a no go for us and I believe it shouldn’t even be discussed whether its a good a idea or not, the receiver’s server should handle any such operations.

How would you format the following POST request body to be in accordance with json api’s specs?

{
  "customer": {
    "first_name": "Sean",
    "last_name": "Donnel",
    "address": "address"
  },
  "passengers": [
    {
      "first_name": "Sean",
      "last_name": "Donnel",
      "gender": "M",
      "birth_date": "1980-01-01"
    },
    {
      "first_name": "Alice",
      "last_name": "Donnel",
      "gender": "F",
      "birth_date": "1980-01-01"
    }
  ],
  "accommodations": [
    {
      "accommodation_code": 38,
      "check_in": "2020-11-20"
    }
  ],
  "flights": [
    {
      "flight_code": "FL-123131"
    },
    {
      "flight_code": "FL-123131"
    }
  ]
}

@thewickedrequest
I also had the same problem when was developing the API.
Would like to hear other JSON:API users what they think about next solution that I use and I don’t see any violations of the protocol in my solution.

I am just passing the “raw data” within the relationships and then creating new resources with one request. If we creating new customer this will be:

POST /customer

{
  "data": {
    "type": "customer",
    "attributes": {
        "first_name": "Sean",
        "last_name": "Donnel",
        "address": "address"
    },
    "relationships": {
      "passengers": {
        "data": [
          {
            "type": "passenger",
            "attributes": {
              "first_name": "Sean",
              "last_name": "Donnel",
              "gender": "M",
              "birth_date": "1980-01-01"
            }
          },
          {
            "type": "passenger",
            "attributes": {
               "first_name": "Alice",
               "last_name": "Donnel",
               "gender": "F",
               "birth_date": "1980-01-01"
            }
          }
       ]
      },
      "accomondations": {
        "data": [
          {
            "type": "accomondation",
            "attributes": {
              "accommodation_code": 38,
              "check_in": "2020-11-20"
            }
          }
        ]
      },
      "flights": {
        "data": [
          {
            "type": "flight",
            "attributes": {
              "flight_code": "FL-123131"
            }
          },
          {
            "type": "flight",
            "attributes": {
              "flight_code": "FL-123131"
            }
          }
        ]
      }
    }
  }
}

You probably want to take a look at this proposed extension for JSON:API 1.1: