Port, BaseURI, BasePath In Rest Assured

When our project becomes huge, then it isn't easy to manage their URL endpoints.

To avoid is a clumsy situation, we will be using a baseURI variable from the RestAssured class to have our base URL.

RestAssured.baseURI = "http://chercher.tech/";

Similarly, we have a port from the rest assured class in case if your application is using any port number, then we will be attending this port with our application port number.

RestAssured.port=8080; // port number depends on your app

Usually, the base URL will have the domain as the value, but most of the time we will be using different paths as our API endpoints, so we'll be using path more often, so we can use a basePath variable from the RestAssured class to store the path.

RestAssured.basePath = "sample/api/product";

The complete program for baseURI, port, basePath

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import io.restassured.RestAssured;
class Base{
	@BeforeAll
	public static void init() {
		RestAssured.baseURI = "http://chercher.tech/";
//		RestAssured.port=8080; //commented as our API doesnot use port
		RestAssured.basePath = "sample/api/product";
	}
}
public class FirstTest extends Base{
	@Test
	void test() {
		RestAssured.given()
		.pathParam("tail", "read")
		.when()
		.get("/{tail}")
		.prettyPrint();
	}
}

rest-assured-baseuri-port-basepath

If you think, why should I use a variable from the RestAssure class ?; why Can't I have my variables?; then answer is yes; you can have your variables
About Author :

I am Pavankumar, Having 8.5 years of experience currently working in Video/Live Analytics project.

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions