What is the restful way to represent a resource clone operation in the URL?

后端 未结 5 2148
执笔经年
执笔经年 2020-12-07 23:02

I have REST API that exposes a complex large resource and I want to be able to clone this resource. Assume that the resource is exposed at /resources/{resoureId}

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-07 23:05

    Will just put it out there, if this can be of help to anyone.
    We had a similar scenario, where we were providing "clone vm" as a feature for scaling out on our IaaS offering. So if a user wanted to scale out they would have to hit POST: /vms/vm101 endpoint with request_body being

    {"action": "clone", // Specifies action to take, since our users can do couple of other actions on a vm, like power_off/power_on etc.
     "body": {"name": [vm102, vm103, vm104] // Number of clones to make
              "storage": 50, ... // Optional parameters for specifying differences in specs one would want from the base virtual machine 
              }
    

    and 3 clones of vm101 viz. vm102, vm103 and vm104 would be spinned.

提交回复
热议问题