Make Selenium Easy

REST Assured Tutorial 9 – Let’s Write First POST Request in REST Assured

As a part of End to End REST Assured Tutorial , in this post We will write first POST request in REST assured.

I will strongly recommended you to learn basics of API testing from here.

To learn what is POST request and how can you hit a POST request in Postman tool, must refer this post.

We will automate a POST request named “GetAuth” from Restful Booker. We will perform some validations like status code as well.

GetAuth API takes body as below where you need to pass username and password. If you pass credentials correctly, you will get token else error message.

Let’s start writing a POST request in REST Assured using both BDD and Non-BDD style. We will see multiple ways of writing same test as well.

Passing body to POST request:-

We know that we need to pass a payload ( JSON or XML) to POST request. REST Assured makes it very handy to pass body to request. We can pass body as a String or a JSON file or a XML file or a Java Object or a byte array. We will see all ways in upcoming posts but as of now we will pass body as a String.

Non-BDD Style:-

BDD Style:-

You can clone/download example repo here.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.

You can find all Selenium related post here.
You can find all API manual and automation related posts here.
You can find frequently asked Java Programs here.

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning

5 thoughts on “REST Assured Tutorial 9 – Let’s Write First POST Request in REST Assured

    1. Hey, because example APIs returns 200 on successful post request. It is completely dependent on developers what status code they return. If they return 201, we need to assert as 201.

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.

REST Assured Tutorial 9 – Let’s Write First POST Request in REST Assured

by Amod Mahajan time to read: 2 min
%d bloggers like this: