rest-assuredcucumber-java

RestAssured cannot pass empty/null path param


I was trying to pass path parameter as empty/null in cucumber api testing using restAssured.

e.g. when I call endpoint as >> http://localhost:8093/my-rest-call//instructions

(http://localhost:8093/my-rest-call/{myId}/instructions)

it's giving 404 But I expect 500. In postman it works as expected though

However if the null/empty path parameter at the end. like below I get 500 internal server error as expected.

e.g http://localhost:8093/my-rest-call/instructions/{path param}

Other option I tried was have " " (double quote with space). But in that case restAssured add that space into special characters. (%20)

e.g http://localhost:8093/my-rest-call/%20/instructions

I am using below code in RestAssured

public static Respon

se request(Function<RequestSpecification, Response> method, RequestSpecification spec) {
        RequestSpecification call = rest()
            .spec(spec)
            .log().all().when();
        return method.apply(call)
            .then()
            .log().all()
            .extract().response();
    }

I can see path param as "" (i.e. myId="") in namedPathParameters under RequestSpecification and url as my-rest-call/{myId}/instructions under method

I looked at below

conversation as well

conversation-1

I am using io.rest-assured:rest-assured:3.3.0


Solution

  • Realised that method pathParams in io.rest-assured:rest-assured:4.5.1 we can pass empty string

    i.e.

    RequestSpecification pathParams(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs);
    

    e.g.

    private RequestSpecification request;
    request.pathParams("uriParamName", "");