Last active
September 23, 2022 14:44
-
-
Save luuizeduardo/e8b8390d1135366c671149fb6d58ab56 to your computer and use it in GitHub Desktop.
Service configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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