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

io.joshworks.restclient.request.BaseRequest Maven / Gradle / Ivy

/*
The MIT License

Copyright (c) 2013 Mashape (http://mashape.com)

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package io.joshworks.restclient.request;

import io.joshworks.restclient.http.ClientRequest;
import io.joshworks.restclient.http.HttpResponse;
import io.joshworks.restclient.http.JsonNode;
import io.joshworks.restclient.http.async.Callback;
import io.joshworks.restclient.http.exceptions.RestClientException;

import java.io.InputStream;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;

public abstract class BaseRequest {

    protected HttpRequest httpRequest;
    protected final ClientRequest clientRequest;

    protected BaseRequest(ClientRequest clientRequest) {
        this.clientRequest = clientRequest;
    }

    public HttpRequest getHttpRequest() {
        return this.httpRequest;
    }

    public HttpResponse asString() throws RestClientException {
        return clientRequest.request(httpRequest, String.class);
    }

    public CompletableFuture> asStringAsync() {
        return clientRequest.requestAsync(httpRequest, String.class);
    }

    public void asStringAsync(Callback callback) {
        clientRequest.requestAsync(httpRequest, String.class, callback);
    }

    public HttpResponse asJson() throws RestClientException {
        return clientRequest.request(httpRequest, JsonNode.class);
    }

    public CompletableFuture> asJsonAsync() {
        return clientRequest.requestAsync(httpRequest, JsonNode.class);
    }

    public Future> asJsonAsync(Callback callback) {
        return clientRequest.requestAsync(httpRequest, JsonNode.class, callback);
    }

    public  HttpResponse asObject(Class responseClass) throws RestClientException {
        return clientRequest.request(httpRequest, responseClass);
    }

    public  CompletableFuture> asObjectAsync(Class responseClass) {
        return clientRequest.requestAsync(httpRequest, responseClass);
    }

    public  Future> asObjectAsync(Class responseClass, Callback callback) {
        return clientRequest.requestAsync(httpRequest,responseClass, callback);
    }

    public HttpResponse asBinary() throws RestClientException {
        return clientRequest.request(httpRequest, InputStream.class);
    }

    public CompletableFuture> asBinaryAsync() {
        return clientRequest.requestAsync(httpRequest, InputStream.class);
    }

    public Future> asBinaryAsync(Callback callback) {
        return clientRequest.requestAsync(httpRequest, InputStream.class, callback);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy