Skip to content

Instantly share code, notes, and snippets.

@luuizeduardo
Last active September 23, 2022 14:44
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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