Udemy REST Assured free

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

package com.pb.rest.presentation;

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 = "https://reqres.in/";
		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.

Handle HTTP PATH Parameters in Get Request using REST Assured