Define request body and response with RAML

For requests with HTTP methods of POST, PUT, DELETE, usually we will need to define the request body. With RAML, how we will define the structure of the request body and how to define the response with RAML. In this tutorial, let’s find out together!

Suppose I define a request to add new student information with the following initial content:

To define the request body for this request, we will declare an additional section body with content-type, data type, and an example for this request body. Examples are as follows:

As you can see, I have defined the content-type for the data in the request body in my example as application/json with the data type of Student as follows:

To define the response for a request in RAML, we will use the responses section.

RAML allows us to define response for each HTTP  status code and for each response, similar to the request body, we can also define response body. Examples are as follows:

As you can see, right after declaring the section for the HTTP status code, we will declare the section body to declare the content of the response body. We can also declare content-type, data type, example similar to the request body.

Add Comment