Package io.mailtrap.http
Interface CustomHttpClient
- All Known Implementing Classes:
DefaultMailtrapHttpClient
public interface CustomHttpClient
Interface representing a custom HTTP client for accessing API.
Default implementation
DefaultMailtrapHttpClient uses Java's HttpClient
Implement your own client to use different http client or handle API communications in a different manner and pass it via MailtrapConfig
-
Method Summary
Modifier and TypeMethodDescriptiondefault StringappendUrlParams(String url, Map<String, ? extends Optional<?>> urlParams) Appends query parameters to the given URL.<T> Tdelete(String url, RequestData requestData, Class<T> responseType) <T> Tget(String url, RequestData requestData, Class<T> responseType) <T> List<T>getList(String url, RequestData requestData, Class<T> responseType) <T> Thead(String url, RequestData requestData, Class<T> responseType) <T,V extends AbstractModel>
Tpatch(String url, V data, RequestData requestData, Class<T> responseType) <T,V extends AbstractModel>
Tpost(String url, V data, RequestData requestData, Class<T> responseType) <T,V extends AbstractModel>
Tput(String url, V data, RequestData requestData, Class<T> responseType)
-
Method Details
-
get
- Type Parameters:
T- Return type- Parameters:
url- Request urlrequestData- Additional request data - headers and query parametersresponseType- Return class type- Returns:
- Response type
- Throws:
HttpException- in case any error. Might throw specificHttpClientExceptionfor HTTP response codes 4xx orHttpServerExceptionfor HTTP response codes 5xx
-
getList
<T> List<T> getList(String url, RequestData requestData, Class<T> responseType) throws HttpException - Type Parameters:
T- Return type- Parameters:
url- Request urlrequestData- Additional request data - headers and query parametersresponseType- Return class type- Returns:
- Response type
- Throws:
HttpException- in case any error. Might throw specificHttpClientExceptionfor HTTP response codes 4xx orHttpServerExceptionfor HTTP response codes 5xx
-
delete
- Type Parameters:
T- Return type- Parameters:
url- Request urlrequestData- Additional request data - headers and query parametersresponseType- Return class type- Returns:
- Response type
- Throws:
HttpException- in case any error. Might throw specificHttpClientExceptionfor HTTP response codes 4xx orHttpServerExceptionfor HTTP response codes 5xx
-
head
- Type Parameters:
T- Return type- Parameters:
url- Request urlrequestData- Additional request data - headers and query parametersresponseType- Return class type- Returns:
- Response type
- Throws:
HttpException- in case any error. Might throw specificHttpClientExceptionfor HTTP response codes 4xx orHttpServerExceptionfor HTTP response codes 5xx
-
post
<T,V extends AbstractModel> T post(String url, V data, RequestData requestData, Class<T> responseType) throws HttpException - Type Parameters:
T- Return typeV- Request type- Parameters:
url- Request urldata- Request body. By default, would be converted to string usingAbstractModel.toJson()requestData- Additional request data - headers and query parametersresponseType- Return class type- Returns:
- Response type
- Throws:
HttpException- in case any error. Might throw specificHttpClientExceptionfor HTTP response codes 4xx orHttpServerExceptionfor HTTP response codes 5xx
-
put
<T,V extends AbstractModel> T put(String url, V data, RequestData requestData, Class<T> responseType) throws HttpException - Type Parameters:
T- Return typeV- Request type- Parameters:
url- Request urldata- Request body. By default, would be converted to string usingAbstractModel.toJson()requestData- Additional request data - headers and query parametersresponseType- Return class type- Returns:
- Response type
- Throws:
HttpException- in case any error. Might throw specificHttpClientExceptionfor HTTP response codes 4xx orHttpServerExceptionfor HTTP response codes 5xx
-
patch
<T,V extends AbstractModel> T patch(String url, V data, RequestData requestData, Class<T> responseType) throws HttpException - Type Parameters:
T- Return typeV- Request type- Parameters:
url- Request urldata- Request body. By default, would be converted to string usingAbstractModel.toJson()requestData- Additional request data - headers and query parametersresponseType- Return class type- Returns:
- Response type
- Throws:
HttpException- in case any error. Might throw specificHttpClientExceptionfor HTTP response codes 4xx orHttpServerExceptionfor HTTP response codes 5xx
-
appendUrlParams
Appends query parameters to the given URL.- Parameters:
url- The base URLurlParams- A map containing query parameters to append to the URL. The keys represent parameter names, and the values represent optional parameter values. If a parameter value is absent, it will be skipped.- Returns:
- The URL with appended query parameters. If no parameters are provided, returns the original URL unchanged.
-