]> git.basschouten.com Git - openhab-addons.git/blob
8877d843aaf6dac3e6c3591f13c3583af2868607
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.salus.internal.rest;
14
15 import java.util.List;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19
20 /**
21  * @author Martin GrzeĊ›lowski - Initial contribution
22  */
23 @NonNullByDefault
24 public interface RestClient {
25     /**
26      * GET request to server
27      * 
28      * @param url to send request
29      * @param headers to send
30      * @return response from server
31      */
32     @Nullable
33     String get(String url, @Nullable Header... headers) throws SalusApiException;
34
35     /**
36      * POST request to server
37      * 
38      * @param url to send request
39      * @param headers to send
40      * @param content to send
41      * @return response from server
42      */
43     @Nullable
44     String post(String url, Content content, @Nullable Header... headers) throws SalusApiException;
45
46     /**
47      * Represents content with a body and a type.
48      */
49     record Content(String body, String type) {
50         /**
51          * Creates a Content instance with the given body and default type ("application/json").
52          *
53          * @param body The content body.
54          */
55         public Content(String body) {
56             this(body, "application/json");
57         }
58     }
59
60     /**
61      * Represents an HTTP header with a name and a list of values.
62      */
63     record Header(String name, List<String> values) {
64         /**
65          * Creates a Header instance with the given name and a single value.
66          *
67          * @param name The header name.
68          * @param value The header value.
69          */
70         public Header(String name, String value) {
71             this(name, List.of(value));
72         }
73     }
74 }