Srivatsan Sundararajan
Senior Manager, QA for MyEclipse, DevStyle and CodeTogether.
Senior Manager, QA for MyEclipse, DevStyle and CodeTogether.
#%RAML 0.8 title: MyBlog RAML baseUri: http://myblog.com/{version} version: v1title (required)—The title property is a short plain text description of the RESTful API. baseUri (optional during development, required after implementation)—The use of the baseUri field is optional to allow describing APIs that have not yet been implemented. After the API is implemented (even a mock implementation) and can be accessed at a service endpoint, the API definition must contain a baseUri property. version (optional)—If the RAML API definition is targeted to a specific API version, the API definition must contain a version.
#%RAML 0.8 title: MyBlog RAML baseUri: http://myblog.com/{version} version: v1 /posts:Resources have to be preceded by a forward slash (/) and end with a colon (:). Any methods and parameters nested under these top level resources belong to and act upon that resource. The post resource defined above is accessible at http://myblog.com/v1/posts. Notice that the final URL to the resource is based on the information provided in the document root section.
#%RAML 0.8 title: MyBlog RAML baseUri: http://myblog.com/{version} version: v1 /posts: /authors: /readers: /comments:Similar to the root resource, nested resources can be accessed using http://myblog.com/v1/posts/authors. Even if the API has several nested resources defined, they can be easily accessed with the URL similar to the above making it very easy for the API developers and consumers to access any nested resource.
#%RAML 0.8 title: MyBlog RAML baseUri: http://myblog.com/{version} version: v1 /posts: /authors: /readers: /comments: get: post: put: delete:
/posts: /{id}: /{title}: /{content}: /{post}: /{id}: /{author}: /{id}: /{authorName}: /authors: /{id}: /{authorName}: /readers: /{id}: /{readername}: /{commentid}: /comments: /{commentid}:To access an individual post, say post with id=1, the URL is http://myblog.com/v1/posts/1. This type of referencing is also applicable to individual nested resources.
#%RAML 0.8 title: MyBlog RAML baseUri: http://myblog.com/{version} version: v1 /posts: /authors: /readers: /comments: get: queryParameters: id: type: Integer description: The id of the post required: true title: type: String description: The title of the post required: true author: type: String description: The author of the post required: true date: type: Date description: The date of creation of the post post: queryParameters: access_token: type: string description: Access Token required: true put: queryParameters: access_token: type: string description: Access Token required: true delete: queryParameters: id: type: String description: The title of the post required: true title: type: String description: The title of the post required: true author: type: String description: The author of the post required: true date: type: Date description: The date of creation of the postNow, let’s add query parameters for all our nested resources like the ones shown in the following example. Refer to the sample file to view all nested resources that require query parameters.
#%RAML 0.8 title: MyBlog RAML baseUri: http://myblog.com/{version} version: v1 /posts: /{id}: get: queryParameters: id: type: Integer description: The id of the post required: true delete: queryParameters: id: type: Integer description: The id of the post required: true /{title}: get: queryParameters: title: type: String description: Get post by title required: true delete: queryParameters: title: type: String description: Get post by title required: true
/posts: /{id}: get: queryParameters: id: type: Integer description: The id of the post required: true responses: 200: body: application/json: example: | { "data": { "id": "postID", "title": "My Post", "author": "Foo", "date": 1341533193, "content": "Sample content", }, "success": true, "status": 200 } application/xml:
traits: - secured: usage: Apply this to any method that needs to be secured description: Some requests require authentication. queryParameters: access_token: description: Access Token type: string example: ACCESS_TOKEN required: true - searchable: usage: Apply this to enable search support description: Blog can be searched for posts, authors. queryParameters: query: description: search query type: string - paged: usage: Apply this to any method that produces results and requires pagination description: Some requests require authentication. queryParameters: start: description: The first page to return type: number pages: description: The number of pages to return type: number - orderable: usage: Apply this to any method that produces results and requires ordering in any format description: Some requests require authentication. queryParameters: orderBy: description: Test type: string required: false order: description: Order enum: [desc, asc] default: desc required: falseTraits can be used across resources like below:
/posts: is: [searchable] /{id}: get: queryParameters: id:
/{authorName}: is: [searchable, paged, orderable] get: queryParameters:You can copy the following attachment into an existing project to get a look at the completed RAML file with all of the traits.