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

com.lyncode.testy.http.UrlBuilder Maven / Gradle / Ivy

There is a newer version: 1.0.1
Show newest version
package com.lyncode.testy.http;

import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.message.BasicNameValuePair;

import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;

public class UrlBuilder {
    public static UrlBuilder path(String path) {
        return new UrlBuilder(path);
    }

    private final String path;
    private List parameters = new ArrayList<>();

    UrlBuilder(String path) {
        this.path = path;
    }

    public UrlBuilder withParameter(String name, String value) {
        parameters.add(new BasicNameValuePair(name, value));
        return this;
    }

    String build (String baseUrl) {
        try {
            return new URIBuilder(baseUrl)
                    .setPath(path)
                    .setParameters(parameters)
                    .build()
                    .toString();
        } catch (URISyntaxException e) {
            throw new RuntimeException(e);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy