简体   繁体   中英

REST create subresources in the same transaction.(RESTEasy)

Consider the scenerio, Have an Object called Device, device could have multiple parameters associated to it which could be of multiple types.

base-device-param (/xx/yy/4/base-device-param)
device-param-type1 extends base-resource-param (/xx/yy/{device-id}/device-param-type1) 
device-param-type2 extends base-resource-param (/xx/yy/{device-id}/device-param-type2)

With the RESTFul way of handling inheritence, the base type and each sub-type will have their own URI and their own schema (as mentioned above).

When I create a device, as you know, A POST operation will be made on /xx/yy.

At the time of creation, we have to associate the parameters to the device. Adding device parameters cant be a different transaction. These parametes are contained by the device and is not an association. so I cant create the parameters prior.

Should I go for RPC like approach or is there a strict REST way of handling this?

By the way, I use RESTEasy if case if you are going to suggest Batch operation.

Include the parameters in the device representation.

<device>
  <id>d123</id>
  <!-- more device properties -->

  <parameters>
    <param>
      <key>foo</key>
      <value>bar</value>
    </param>
    <param>
      <key>baz</key>
      <value>qux</value>
    </param>
    <!-- more parameters>
  </parameters>
</device>

Your REST resource will have to map this representation to Java classes. What you do with them, if and how you store them, is up to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM