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

com.bandwidth.http.request.HttpRequest Maven / Gradle / Ivy

Go to download

The official client SDK for Bandwidth's Voice, Messaging, MFA, and WebRTC APIs

There is a newer version: 12.0.1
Show newest version
/*
 * BandwidthLib
 *
 * This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
 */

package com.bandwidth.http.request;

import com.bandwidth.http.Headers;
import java.util.AbstractMap.SimpleEntry;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Class for creating and managing HTTP Requests.
 */
public class HttpRequest {

    /**
     * Private store for properties.
     */
    private HttpMethod httpMethod;
    private Headers headers;
    private StringBuilder queryUrlBuilder;
    private List> parameters;
    private Map queryParameters;

    /**
     * Initializes a simple http request.
     * @param method           The HTTP method to use. Can be GET, HEAD, PUT, POST, DELETE and PATCH
     * @param queryUrlBuilder  The fully qualified absolute http url to create the HTTP Request.
     * @param headers          The key-value map of all http headers to be sent
     * @param queryParameters  The query parameters in a key-value map
     * @param parameters       The form data values in a key-value map
     */
    public HttpRequest(HttpMethod method, StringBuilder queryUrlBuilder, Headers headers, 
             Map queryParameters, List> parameters) {
        this.httpMethod = method;
        this.queryUrlBuilder = queryUrlBuilder;
        this.headers = headers;
        this.queryParameters = queryParameters;
        this.parameters = parameters;
    }

    /**
     * HttpMethod for the http request.
     * @return HttpMethod
     */
    public HttpMethod getHttpMethod() {
        return httpMethod;
    }

    /**
     * Headers for the http request.
     * @return Headers
     */
    public Headers getHeaders() {
        return headers;
    }

    /**
     * Query url for the http request.
     * @return String query url
     */
    public String getQueryUrl() {
        return queryUrlBuilder.toString();
    }

    /**
     * Parameters for the http request.
     * @return List of simple entries for form parameters
     */
    public List> getParameters() {
        return parameters;
    }

    /**
     * Query parameters for the http request.
     * @return Map of queryParameters
     */
    public Map getQueryParameters() {
        return queryParameters;
    }

    /**
     * Add Query parameter in http request.
     * @param key   The key of query parameter to be added
     * @param value The value for respective query parameter
     */
    public void addQueryParameter(String key, Object value) {
        if (key == null || key.isEmpty() || value == null) {
            return;
        }
        if (queryParameters == null) {
            queryParameters = new HashMap();
        }
        queryParameters.put(key, value);
    }

    /**
     * Converts this HttpRequest into string format.
     * @return String representation of this class
     */
    @Override
    public String toString() {
        return "HttpRequest [httpMethod=" + httpMethod + ", headers=" + headers
                + ", queryUrlBuilder=" + queryUrlBuilder + ", queryParameters=" + queryParameters
                + ", parameters=" + parameters + "]";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy