0

I need to support different ways of adding a component to a collection of components:

  • adding "blank" component,
  • adding a component which is an instance of a class
  • adding a component which is a copy of another component (paste).
    Each way requires different data from the user.

    A POST on the collection seems natural, but how do I support the different ways to add a component? It seems as if one verb (POST) is not enough to describe the 3 different operations required (add new, add instance, add copy).

    How should this be achieved in a RESTful way?
  • 1 Answers1

    0

    If the different ways you describe create the same "kind" of resource, then I can image the following ways (if not, these really should be different collections):

    One way is to just use a single representation to describe how to create the given resource, something like:

    {
       "copy": {
           "href": "copy-from-this-uri"
       },
       "instance-of": "something"
    }
    

    Leave it empty to create an empty resource, etc. Another way would be to use completely different mime-types for the 3 different use-cases for the same POST.

    Robert Bräutigam
    • 7,514
    • 1
    • 20
    • 38