RAML definition reusable sub-route
Asked Answered
S

1

8

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.

Solfa answered 13/2, 2017 at 15:48 Comment(0)
D
3

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

Dragonroot answered 13/2, 2017 at 17:57 Comment(1)
Unfortunately, this doesn't seem to work well. RecourceTypes are there as a level of abstraction in the form of inheritance. What I want is to add a custom subroute to different endpoints. Traits don't seem to work well either.Solfa

© 2022 - 2024 — McMap. All rights reserved.