Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Executive summary: Either is fine. I'd go with #1 with the caveat that you do it in at least two, possibly three requests. One to PUT the car, followed by another to POST the owner/driver. If you don't have the full resource data for the car beforehand, do a GET for that before the PUT, updating your PUT request body as necessary. If the GET returns 404, then just leave the unknown fields blank in your PUT, and define that your server will fill them in with default values (rather than, say, reject the PUT request).</p> <p>Long answer:</p> <p>REST does not dictate what the format of your message body should be.<br> The only constraints REST incurs upon you are:</p> <ol> <li>The uniform interface, in this case, HTTP's <code>POST</code> method. Using POST means you intend to append a new resource defined by the request body to the collection identified by the target URI. If doing so requires that the server must also create a resource elsewhere, then so be it.</li> <li>A documented, preferably common media type. Either use an existing media type (e.g. <a href="http://stateless.co/hal_specification.html" rel="nofollow" title="HAL Specification">application/hal+json</a>) or document the one you create.</li> <li>Use hypermedia (i.e. links) to advance the application state (browser window). In the request body, you can send whatever you like. It is the server's responsibility in its response to provide a hyperlink between car and person.</li> <li>The request must be self-contained. This means that you cannot, say, send one request to "set the current car to 66H8800" and then a second request to "create a driver for the currently set car". Doing this requires server state to be remembered between requests, which is forbidden in REST (as it breaks many things, like load balancing). It appears you are not doing this, but I can't tell from the code provided.</li> </ol> <p>It is your media type that dictates whether or not a "license" key should exist. Choose or create one as you see fit.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload