Skip to main content

Handle HTTP PATH Parameters in Get Request using REST Assured

Also known as Template parameters, path parameters are placed within the path of an endpoint just before the query string, and they provide developers with an effective way to parameterize resources. Path parameters are used to identify a resource uniquely.

Example Code


import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import io.restassured.RestAssured;
import io.restassured.response.Response;

import static io.restassured.RestAssured.given;

public class ReqRes 
	String id = "1";
	public void setup()
		RestAssured.baseURI = "";
		RestAssured.basePath = "api/users";
	public void pathParametersExample()
		Response res = 
			.pathParam("id", id)

Here Response is an interface. To get the Response object from the HTTP Request then, once we have the Response object we can easily get its body as a String. Here, body will return  response body. Pretty-print the response body if possible and return it as string. Mainly useful for debug purposes when writing tests. Pretty printing is possible for content-types JSON, XML and HTML.

Submitted by tgoswami on September 1, 2020

Tarun has 11+ years of experience in Quality Assurance in different domains like Banking, E-commerce, Health and Education.


At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.