Make Selenium Easy

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

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 ”“. Actually this is base URI of Google. Now append “/maps” in last of base url “” as ““. 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:-

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.

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

A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.

3 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.