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

io.induct.rest.Request Maven / Gradle / Ivy

The newest version!
package io.induct.rest;

import com.google.common.collect.Multimap;
import io.induct.http.HttpClient;
import io.induct.http.Response;

import java.io.InputStream;

/**
 * @since 2015-05-09
 */
public class Request {

    private final HttpClient http;
    private final String url;
    private final Multimap headers;
    private final Multimap params;
    private final InputStream body;

    public Request(HttpClient http, String url, Multimap headers, Multimap params, InputStream body) {
        this.http = http;
        this.url = url;
        this.headers = headers;
        this.params = params;
        this.body = body;
    }

    public Response get() {
        return call(http::get);
    }

    public Response post() {
        return call(http::post);
    }

    public Response put() {
        return call(http::put);
    }

    public Response delete() {
        return call(http::delete);
    }

    public HttpClient getHttp() {
        return http;
    }

    public String getUrl() {
        return url;
    }

    public Multimap getHeaders() {
        return headers;
    }

    public Multimap getParams() {
        return params;
    }

    public InputStream getBody() {
        return body;
    }

    protected Response call(Method m) {
        return m.call(url, params, headers, body);
    }

    protected interface Method {
        Response call(String url, Multimap params, Multimap headers, InputStream body);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy