Java Path to URL getUri(String baseApiUrl, String path)

Here you can find the source of getUri(String baseApiUrl, String path)

Description

Gets the absolute URL to use to invoke a rest API at a given path.

License

Open Source License

Parameter

Parameter Description
path a parameter

Exception

Parameter Description
URISyntaxException an exception

Declaration

protected static URI getUri(String baseApiUrl, String path) throws URISyntaxException 

Method Source Code

//package com.java2s;

import java.net.URI;
import java.net.URISyntaxException;

public class Main {
    /**/* w ww .  j  av  a 2  s.c o m*/
     * Gets the absolute URL to use to invoke a rest API at a given path.
     *
     * @param path
     * @throws URISyntaxException
     */
    protected static URI getUri(String baseApiUrl, String path) throws URISyntaxException {
        if (baseApiUrl.endsWith("/")) {
            baseApiUrl = baseApiUrl.substring(0, baseApiUrl.length() - 1);
        }
        if (path == null) {
            return new URI(baseApiUrl);
        } else {
            return new URI(baseApiUrl + path);
        }
    }
}

Related

  1. fileToURIString(File file)
  2. getUriNormalizedContainerAndPathWithoutSlash(String stringUriValue, String containerUrl, boolean normalizeUrlMode, boolean matchBaseUrlMode)
  3. getURL(String aPath)
  4. getUrl(String baseUrl, String absPath)
  5. getURL(String host, int port, String path, boolean isHTTPS)