Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RAML definition reusable sub-route

Tags:

rest

raml

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.

like image 805
html_programmer Avatar asked Feb 13 '17 15:02

html_programmer


People also ask

What should the first line of a RAML API definition contain?

The first line of a RAML API definition document MUST begin with the text #%RAML followed by a single space followed by the text 1.0 and nothing else before the end of the line.

How do you define a library in RAML?

A RAML library is a collection of the data type declaration, security scheme declaration, and resource type declaration into a modular and reusable group.

What are the types in RAML?

In a RAML file, we can define simple and complex data types. Some properties are defined as data types. For example, the property modelTree in the type Brochure is a ModelTree data type.


1 Answers

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

like image 200
Daniel Valls Estella Avatar answered Oct 06 '22 02:10

Daniel Valls Estella