All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pl.codewise.samples.spring.client.RestClient Maven / Gradle / Ivy

There is a newer version: 1.4.3
Show newest version
package pl.codewise.samples.spring.client;

import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import pl.codewise.samples.spring.webapp.rest.model.Response;

import java.net.URI;

public class RestClient {

    private final RestTemplate client;
    private String endpoint;

    public RestClient(RestTemplate client, String endpoint) {
        this.client = client;
        this.endpoint = endpoint;
    }

    public Response askGoogle(String query) {
        URI uri = UriComponentsBuilder.fromUriString(endpoint + "/v1/google")
                .queryParam("q", query)
                .build()
                .toUri();
        return client.getForObject(uri, Response.class);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy