Make Selenium Easy

REST Assured Tutorial 14 – BaseURI and BasePath – Introduction and Configuration

Last updated on December 12th, 2019 at 02:59 pm

As a part of End to End REST Assured Tutorial , in this post We will learn about BaseURI and BasePath in Rest Assured.

We have already written CRUD operations in Rest Assured and you must have noticed I have used “baseUri()” method to set the API URI. You may have thought that API URI is Base URI which is not correct.

We all know about Google whose URL is ” https://www.google.com/“. Actually this is base URI of Google. Now append “/maps” in last of base url “https://www.google.com/” as “https://www.google.com/maps“. Google will launch Google Maps. Try same with “/news”. Google will launch Google News. Here “Maps” and “News” are actually resources which are called as base path. So to summarize, BaseURI is the address where different resources are located. A Base Path which is appended with BaseURI to locate a resource.

If we see RestFul Booker API doc, we can easily find BaseURI and BasePath:-

https://restful-booker.herokuapp.com/auth

https://restful-booker.herokuapp.com/booking

https://restful-booker.herokuapp.com/ping

Above, Underlined string is BaseURI and bold string is BasePath.

RestAssured provides multiple ways to setup BaseURI and BasePath. We can setup BaseURI and BasePath for individual request as well as for multiple requests at once.

Setting BaseURI and BasePath for individual request:-

To set for specific request, we can use methods provided by RequestSpecification interface. See an example below :-

Setting BaseURI and BasePath at global level:-

If we have same BaseURI and BasePath for all or a group of requests , mentioning again and again for each request is not a good practice. Rest Assured provides global set up of BaseURI and BasePath so that it will be applicable for all required requests. We need to use RestAssured class for it. It provides static fields to set BaseUri and BasePath. See an example below:-

We will see complete programs now.

Individual request level setup:-

Global setup :-

Output will be same for both programs:-

We can also store BaseUri and BasePath in Strings and use it wherever required. It will be helpful in managing and maintaining data.

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.
#ThanksForReading
#HappyLearning

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

2 thoughts on “REST Assured Tutorial 14 – BaseURI and BasePath – Introduction and Configuration

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 14 – BaseURI and BasePath – Introduction and Configuration

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