8
votes

Our api will have a reusable /posts subroute that will apply to different top-level routes.

For example:

/me/posts 
/users/{user-id}/posts
... 

Example for posts:

/posts 
    /{post-id}
        /likes 
        /comments 
            /{comment-id}
... 

Posts will have fixed subroutes, parameters etc as well.
What is the standard way to define such a default, reusable subroute with RAML?

Of course, one could decide to turn this around and make a /posts endpoint, but I don't think that the API definition should be changed based on RAML capabilities. Also, I should be able to have multiple endpoints pointing to the same resource, if I wanted it to.

If you have an answer, please share an example according the requirements.

1

1 Answers

3
votes

You can define a ResourceType and specify you are using it in many places. You can do this in the same file or in an external file opreating as a Library.

http://raml.org/developers/whats-new-raml-10