Make Selenium Easy

REST Assured Tutorial 19 – Default Host And Port in Rest Assured

As a part of End to End REST Assured Tutorial , in this post We will learn about “Default Host and Port in Rest Assured”.

A port is a communication endpoint where a service is available. For example if we install Jenkins on a server or local , we start it at a specific port and using that port we access Jenkins. So if you have some services running on a specific port, you need to pass that in URI so that request could hit to correct endpoint. Final BaseURI is created by appending port with colon as prefix .

Example:- http://localhost:8080/

Before going further, let’s hit a request and observe output:-


In output, you will see a line as below:-

By default REST assured assumes host localhost and port 8080 when doing a request. It means if we not provide any host and port, it will take default values. It is an interview question.

We can always override it to pass desired URI. We have seen already setting a BaseURI earlier. Setting up port is also similar.

We can setup a port in below ways:-

Using RequestSpecification

BDD Style:-

RequestSpecification interface has a method named port(). We can use that to set a desired port number.

Non-BDD Style:-

Using RequestSpecificationBuilder

Using static property of RestAssured class

This way will set port number for all subsequent request.

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.

Table of Contents

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

1 thought on “REST Assured Tutorial 19 – Default Host And Port in Rest Assured

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 19 – Default Host And Port in Rest Assured

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