Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*-
* #%L
* rapidoid-http-client
* %%
* Copyright (C) 2014 - 2017 Nikolche Mihajlovski and contributors
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package org.rapidoid.http;
import org.rapidoid.annotation.Authors;
import org.rapidoid.annotation.Since;
import org.rapidoid.commons.Err;
import org.rapidoid.concurrent.Callback;
import org.rapidoid.concurrent.Future;
import org.rapidoid.config.Config;
import org.rapidoid.config.RapidoidInitializer;
import org.rapidoid.util.Msc;
@Authors("Nikolche Mihajlovski")
@Since("4.1.0")
public class REST extends RapidoidInitializer {
public static final RESTClient DEFAULT_CLIENT = new RESTClient();
public static Future get(String uri, Class resultType, Callback callback) {
return DEFAULT_CLIENT.get(uri, resultType, callback);
}
public static T get(String uri, Class resultType) {
return DEFAULT_CLIENT.get(uri, resultType);
}
public static Future post(String uri, Class resultType, Callback callback) {
return DEFAULT_CLIENT.post(uri, resultType, callback);
}
public static T post(String uri, Class resultType) {
return DEFAULT_CLIENT.post(uri, resultType);
}
public static Future put(String uri, Class resultType, Callback callback) {
return DEFAULT_CLIENT.put(uri, resultType, callback);
}
public static T put(String uri, Class resultType) {
return DEFAULT_CLIENT.put(uri, resultType);
}
public static Future delete(String uri, Class resultType, Callback callback) {
return DEFAULT_CLIENT.delete(uri, resultType, callback);
}
public static T delete(String uri, Class resultType) {
return DEFAULT_CLIENT.delete(uri, resultType);
}
public static Future patch(String uri, Class resultType, Callback callback) {
return DEFAULT_CLIENT.patch(uri, resultType, callback);
}
public static T patch(String uri, Class resultType) {
return DEFAULT_CLIENT.patch(uri, resultType);
}
public static Future options(String uri, Class resultType, Callback callback) {
return DEFAULT_CLIENT.options(uri, resultType, callback);
}
public static T options(String uri, Class resultType) {
return DEFAULT_CLIENT.options(uri, resultType);
}
public static Future head(String uri, Class resultType, Callback callback) {
return DEFAULT_CLIENT.head(uri, resultType, callback);
}
public static T head(String uri, Class resultType) {
return DEFAULT_CLIENT.head(uri, resultType);
}
public static Future trace(String uri, Class resultType, Callback callback) {
return DEFAULT_CLIENT.trace(uri, resultType, callback);
}
public static T trace(String uri, Class resultType) {
return DEFAULT_CLIENT.trace(uri, resultType);
}
public static T call(String verb, String uri, Class resultType) {
switch (HttpVerb.from(verb)) {
case GET:
return get(uri, resultType);
case POST:
return post(uri, resultType);
case PUT:
return put(uri, resultType);
case DELETE:
return delete(uri, resultType);
case PATCH:
return patch(uri, resultType);
case OPTIONS:
return options(uri, resultType);
case HEAD:
return head(uri, resultType);
case TRACE:
return trace(uri, resultType);
default:
throw Err.notExpected();
}
}
public static Future call(String verb, String uri, Class resultType, Callback callback) {
switch (HttpVerb.from(verb)) {
case GET:
return get(uri, resultType, callback);
case POST:
return post(uri, resultType, callback);
case PUT:
return put(uri, resultType, callback);
case DELETE:
return delete(uri, resultType, callback);
case PATCH:
return patch(uri, resultType, callback);
case OPTIONS:
return options(uri, resultType, callback);
case HEAD:
return head(uri, resultType, callback);
case TRACE:
return trace(uri, resultType, callback);
default:
throw Err.notExpected();
}
}
public static T client(Class clientInterface) {
return Msc.dynamic(clientInterface, new DynamicRESTClient(clientInterface));
}
public static T client(Class clientInterface, Config config) {
return Msc.dynamic(clientInterface, new DynamicRESTClient(clientInterface, config));
}
}