Code re-use in parent and child resource


#1

I have situation where I need to do the same thing in both parent and child (optional) for eg:

In below example I am duplicating my post as both parent and child require same logic. Is there a way to make this code common to both? In other words how can I reuse the code

/resource:
post:
body:
application/json:
schema: res
responses:
200:
body:
application/json:
schema: create_response
/{resource id}:
post:
body:
application/json:
schema: res
responses:
200:
body:
application/json:
schema: create_response


#2

You can use resourceTypes for it to get something like that:

#%RAML 0.8
title: My API
version: v1.0
baseUri: http://localhost:8082/api/{version}

resourceTypes:
  - postResource:
      post:
        body:
          application/json:
            schema: res
        responses:
          200:
            body:
              application/json:
                schema: create_response

/resource: 
  type: postResource 
  /{resourceid}: 
    type: postResource

You can not only use resourceTypes to create common patterns, but also traits. See RAML Specification for more information.

Hope that helps you?