aboutsummaryrefslogtreecommitdiffstats
path: root/tenant-cd-api/src/main/java/ai/vespa/hosted/cd/Endpoint.java
blob: dd76827dd2b9ad79d997a722fe997910fcdbfe72 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.hosted.cd;

import java.net.URI;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.Map;

/**
 * An endpoint in a Vespa application {@link Deployment}, which allows document retrieval.
 *
 * @author jonmv
 */
public interface Endpoint {

    /** Returns the URI of the endpoint, with scheme, host and port. */
    URI uri();

    /** Returns the authenticator for HTTP requests against this particular endpoint. */
    EndpointAuthenticator authenticator();

    /** Sends the given request with required authentication. */
    <T> HttpResponse<T> send(HttpRequest.Builder request, HttpResponse.BodyHandler<T> handler);

    /** Sends the given request with required authentication. */
    default HttpResponse<String> send(HttpRequest.Builder request) {
        return send(request, HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
    }

    /** Creates a request against the endpoint, with the given path and properties. */
    HttpRequest.Builder request(String path, Map<String, String> properties);

    /** Creates a request against the endpoint, with the given path. */
    default HttpRequest.Builder request(String path) {
        return request(path, Collections.emptyMap());
    }

}