Skip to content

Instantly share code, notes, and snippets.

@luuizeduardo
Last active September 23, 2022 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luuizeduardo/e8b8390d1135366c671149fb6d58ab56 to your computer and use it in GitHub Desktop.
Save luuizeduardo/e8b8390d1135366c671149fb6d58ab56 to your computer and use it in GitHub Desktop.
Service configuration
package org.example.services;
import com.fasterxml.jackson.databind.JsonNode;
import io.restassured.RestAssured;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
@Slf4j
@Service
public class YourApiService {
private RequestSpecification spec;
@PostConstruct
protected void init() {
// On init you can set some global properties of RestAssured
RestAssured.useRelaxedHTTPSValidation();
spec = new RequestSpecBuilder().setBaseUri("https://reqres.in").setBasePath("/api").build();
}
public Response postRequest(String endpoint, JsonNode requestBody) {
return RestAssured.given(spec)
.contentType(ContentType.JSON)
.body(requestBody)
.when()
.post(endpoint);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment