1 package com.atlassian.marketplace.client.http;
2
3 import java.io.Closeable;
4 import java.io.InputStream;
5 import java.net.URI;
6
7 import com.atlassian.marketplace.client.MpacException;
8
9 import com.google.common.collect.Multimap;
10
11 /**
12 * Abstraction of how to execute HTTP requests against the API.
13 * @since 2.0.0
14 */
15 public interface HttpTransport extends Closeable
16 {
17 /**
18 * Performs an HTTP GET.
19 * @param uri URI of resource to get
20 * @return a {@link SimpleHttpResponse} wrapping the HTTP response
21 * @throws MpacException if the server was unavailable or returned no response
22 */
23 SimpleHttpResponse get(URI uri) throws MpacException;
24
25 /**
26 * Performs an HTTP POST with form parameters.
27 * @param uri URI of resource to post to
28 * @param params the unencoded parameters
29 * @return a {@link SimpleHttpResponse} wrapping the HTTP response
30 * @throws MpacException if the server was unavailable or returned no response
31 */
32 SimpleHttpResponse postParams(URI uri, Multimap<String, String> params) throws MpacException;
33
34 /**
35 * Performs an HTTP POST of an API entity.
36 * @param uri URI of resource to post to
37 * @param content input stream containing the request body
38 * @param length length of the input stream
39 * @param contentType content type of the entity
40 * @param acceptContentType expected content type of response
41 * @return a {@link SimpleHttpResponse} wrapping the HTTP response
42 * @throws MpacException if the server was unavailable or returned no response
43 */
44 SimpleHttpResponse post(URI uri, InputStream content, long length, String contentType, String acceptContentType) throws MpacException;
45
46 /**
47 * Performs an HTTP PUT of an API entity. The content type is assumed to be JSON.
48 * @param uri URI of resource to put
49 * @param content request body
50 * @return a {@link SimpleHttpResponse} wrapping the HTTP response
51 * @throws MpacException if the server was unavailable or returned no response
52 */
53 SimpleHttpResponse put(URI uri, byte[] content) throws MpacException;
54
55 /**
56 * Performs an HTTP PATCH. The content type is assumed to be application/json-patch+json.
57 * @param uri URI of resource to put
58 * @param content request body
59 * @return a {@link SimpleHttpResponse} wrapping the HTTP response
60 * @throws MpacException if the server was unavailable or returned no response
61 */
62 SimpleHttpResponse patch(URI uri, byte[] content) throws MpacException;
63
64 /**
65 * Performs an HTTP DELETE.
66 * @param uri URI of resource to delete
67 * @return a {@link SimpleHttpResponse} wrapping the HTTP response
68 * @throws MpacException if the server was unavailable or returned no response
69 */
70 SimpleHttpResponse delete(URI uri) throws MpacException;
71
72 /**
73 * Returns another {@code HttpTransport} instance that behaves the same as this one except that
74 * it adds headers from the specified {@link RequestDecorator} to every request (in
75 * addition to any headers previously specified in the defaults). The new instance still
76 * uses the same underlying HTTP transport; closing one will close the other.
77 * @param decorator will generate additional headers for requests made via the new instance
78 * @return a new {@link HttpTransport} instance
79 */
80 HttpTransport withRequestDecorator(RequestDecorator decorator);
81 }