
org.rapidoid.http.RESTClient 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.Callbacks;
import org.rapidoid.concurrent.Future;
import org.rapidoid.concurrent.Futures;
@Authors("Nikolche Mihajlovski")
@Since("4.1.0")
public class RESTClient {
public Future get(String uri, Class resultType, Callback callback) {
RESTResultMapper mapper = new RESTResultMapper(resultType);
Callback cb = Callbacks.mapping(callback, mapper);
return Futures.mapping(HTTP.get(uri, cb), mapper);
}
public T get(String uri, Class resultType) {
return (T) get(uri, resultType, null).get();
}
public Future post(String uri, Class resultType, Callback callback) {
RESTResultMapper mapper = new RESTResultMapper(resultType);
Callback cb = Callbacks.mapping(callback, mapper);
return Futures.mapping(HTTP.post(uri, null, new byte[0], null, cb), mapper);
}
public T post(String uri, Class resultType) {
return (T) post(uri, resultType, null).get();
}
// public Future put(String uri, Class resultType, Callback callback) {
// RESTResultMapper mapper = new RESTResultMapper(resultType);
// Callback cb = Callbacks.mapping(callback, mapper);
// return Futures.mapping(HTTP.put(uri, cb), mapper);
// }
//
// public T put(String uri, Class resultType) {
// return (T) put(uri, resultType, null).get();
// }
//
// public Future delete(String uri, Class resultType, Callback callback) {
// RESTResultMapper mapper = new RESTResultMapper(resultType);
// Callback cb = Callbacks.mapping(callback, mapper);
// return Futures.mapping(HTTP.delete(uri, cb), mapper);
// }
//
// public T delete(String uri, Class resultType) {
// return (T) delete(uri, resultType, null).get();
// }
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy