
org.rapidoid.http.REST Maven / Gradle / Ivy
The newest version!
package org.rapidoid.http;
/*
* #%L
* rapidoid-rest
* %%
* Copyright (C) 2014 - 2016 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%
*/
import org.rapidoid.annotation.Authors;
import org.rapidoid.annotation.Since;
import org.rapidoid.concurrent.Callback;
import org.rapidoid.concurrent.Future;
import org.rapidoid.u.U;
@Authors("Nikolche Mihajlovski")
@Since("4.1.0")
public class REST {
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 T call(String verb, String uri, Class resultType) {
if ("GET".equalsIgnoreCase(verb)) {
return get(uri, resultType);
} else if ("POST".equalsIgnoreCase(verb)) {
return post(uri, resultType);
} else {
// FIXME support PUT and DELETE
throw U.rte("Unsupported REST verb: '%s'", verb);
}
}
public static Future call(String verb, String uri, Class resultType, Callback callback) {
if ("GET".equalsIgnoreCase(verb)) {
return get(uri, resultType, callback);
} else if ("POST".equalsIgnoreCase(verb)) {
return post(uri, resultType, callback);
} else {
// FIXME support PUT and DELETE
throw U.rte("Unsupported REST verb: '%s'", verb);
}
}
public static T client(Class clientInterface) {
return U.dynamic(clientInterface, new DynamicRESTClient(clientInterface));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy