How do you model an action in RAML

209 Views Asked by At

I would like to understand what is the best approach for modeling an action on a resource using RAML.

E.g. I have the following resource definition in RAML:

/orders:
  type: collection
  get:
    description: Gets all orders
  post:
    description: Creates a new order

  /{orderId}:
    type: element
    get:
      description: Gets a order

    put:
      description: Updates a order

    delete:
      description: Deletes a order

Now for an order I would like to model an "approve" action. Is there a best practice of doing this with RAML ?

2

There are 2 best solutions below

0
On BEST ANSWER
  • You could PUT or PATCH for setting some "Approval" to true in your model.
  • You could think about the approval as a resource. For example:

    /orders:
      type: collection
      get:
      post:
      /{orderId}:
        type: element
        get:
        put:
        delete:
        /approval:
          post:
          get:
          ...
    

It's not a RAML best practice. It's more related with how do you represent your model in REST.

0
On

You could use a PATCH request with a "patch document" that raises the approved flag on an order.