Martin Ahrer
Martin Ahrer

Reputation: 1037

How to set the rest-assured basePath through RequestSpecBuilder or RequestSpecification

I know that with rest-assured we can set a base path globally using RestAssured.basePath = "/resource".

However I need to set it locally for a request specification. Anyone tried this, don't see any API for that.

Upvotes: 2

Views: 12714

Answers (2)

Ashwiinn Karaangutkar
Ashwiinn Karaangutkar

Reputation: 171

Below is an example where I have shown how to set a basepath globally.

import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.jayway.restassured.builder.RequestSpecBuilder;
import com.jayway.restassured.http.ContentType;
import com.jayway.restassured.specification.RequestSpecification;
import static com.jayway.restassured.RestAssured.*;

public class RequestSpecificationTest {

RequestSpecification rspec;
RequestSpecBuilder build;

@BeforeClass
public void requestSpec () {

build = new RequestSpecBuilder();
build.setBaseUri ("https://maps.googleapis.com");
build.setBasePath ("maps/api/place/textsearch/json");
build.addParam ("query", "restaurants in mumbai");
build.addParam ("key", "XYZ");

rspec = build.build ();

}

@Test
public void test01 () {

     given()
    .spec (rspec)
    .when ()
    .get ("")
    .then ()
    .contentType (ContentType.JSON)
    .statusCode (200);     
 }

}

You can also follow my tutorial on the same topic: Using RequestSpecBuilder in Rest Assured ( Code Reuse )

Upvotes: 0

Johan
Johan

Reputation: 40510

This is not supported. Please add it as an issue at the issue tracker and state your use case. The closest thing to a work-around would probably be to set a baseUri.

Update: This is now supported in 2.3.2.

Upvotes: 3

Related Questions