use of retrofit2.http.Path in project retrofit by square.
the class JsonQueryParameters method main.
public static void main(String... args) throws IOException, InterruptedException {
MockWebServer server = new MockWebServer();
server.start();
server.enqueue(new MockResponse());
Retrofit retrofit = new Retrofit.Builder().baseUrl(server.url("/")).addConverterFactory(new JsonStringConverterFactory(GsonConverterFactory.create())).build();
Service service = retrofit.create(Service.class);
Call<ResponseBody> call = service.example(new Filter("123"));
Response<ResponseBody> response = call.execute();
// TODO handle user response...
// Print the request path that the server saw to show the JSON query param:
RecordedRequest recordedRequest = server.takeRequest();
System.out.println(recordedRequest.getPath());
server.shutdown();
}
use of retrofit2.http.Path in project retrofit by square.
the class RequestBuilderTest method getWithUnusedAndInvalidNamedPathParam.
@Test
public void getWithUnusedAndInvalidNamedPathParam() {
class Example {
//
@GET("/foo/bar/{ping}/{kit,kat}/")
Call<ResponseBody> method(@Path("ping") String ping) {
return null;
}
}
Request request = buildRequest(Example.class, "pong");
assertThat(request.method()).isEqualTo("GET");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/pong/%7Bkit,kat%7D/");
assertThat(request.body()).isNull();
}
use of retrofit2.http.Path in project retrofit by square.
the class RequestBuilderTest method bodyWithPathParams.
@Test
public void bodyWithPathParams() {
class Example {
//
@POST("/foo/bar/{ping}/{kit}/")
Call<ResponseBody> method(@Path("ping") String ping, @Body RequestBody body, @Path("kit") String kit) {
return null;
}
}
RequestBody body = RequestBody.create(TEXT_PLAIN, "Hi!");
Request request = buildRequest(Example.class, "pong", body, "kat");
assertThat(request.method()).isEqualTo("POST");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/pong/kat/");
assertBody(request.body(), "Hi!");
}
use of retrofit2.http.Path in project azure-sdk-for-java by Azure.
the class EndpointsInner method purgeContentWithServiceResponseAsync.
/**
* Removes a content from CDN.
*
* @param resourceGroupName Name of the Resource group within the Azure subscription.
* @param profileName Name of the CDN profile which is unique within the resource group.
* @param endpointName Name of the endpoint under the profile which is unique globally.
* @param contentPaths The path to the content to be purged. Can describe a file path or a wild card directory.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable for the request
*/
public Observable<ServiceResponse<Void>> purgeContentWithServiceResponseAsync(String resourceGroupName, String profileName, String endpointName, List<String> contentPaths) {
if (resourceGroupName == null) {
throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
}
if (profileName == null) {
throw new IllegalArgumentException("Parameter profileName is required and cannot be null.");
}
if (endpointName == null) {
throw new IllegalArgumentException("Parameter endpointName is required and cannot be null.");
}
if (this.client.subscriptionId() == null) {
throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
}
if (this.client.apiVersion() == null) {
throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
}
if (contentPaths == null) {
throw new IllegalArgumentException("Parameter contentPaths is required and cannot be null.");
}
Validator.validate(contentPaths);
PurgeParameters contentFilePaths = new PurgeParameters();
contentFilePaths.withContentPaths(contentPaths);
Observable<Response<ResponseBody>> observable = service.purgeContent(resourceGroupName, profileName, endpointName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), contentFilePaths, this.client.userAgent());
return client.getAzureClient().getPostOrDeleteResultAsync(observable, new TypeToken<Void>() {
}.getType());
}
use of retrofit2.http.Path in project azure-sdk-for-java by Azure.
the class EndpointsInner method beginPurgeContentWithServiceResponseAsync.
/**
* Removes a content from CDN.
*
* @param resourceGroupName Name of the Resource group within the Azure subscription.
* @param profileName Name of the CDN profile which is unique within the resource group.
* @param endpointName Name of the endpoint under the profile which is unique globally.
* @param contentPaths The path to the content to be purged. Can describe a file path or a wild card directory.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceResponse} object if successful.
*/
public Observable<ServiceResponse<Void>> beginPurgeContentWithServiceResponseAsync(String resourceGroupName, String profileName, String endpointName, List<String> contentPaths) {
if (resourceGroupName == null) {
throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
}
if (profileName == null) {
throw new IllegalArgumentException("Parameter profileName is required and cannot be null.");
}
if (endpointName == null) {
throw new IllegalArgumentException("Parameter endpointName is required and cannot be null.");
}
if (this.client.subscriptionId() == null) {
throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
}
if (this.client.apiVersion() == null) {
throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
}
if (contentPaths == null) {
throw new IllegalArgumentException("Parameter contentPaths is required and cannot be null.");
}
Validator.validate(contentPaths);
PurgeParameters contentFilePaths = new PurgeParameters();
contentFilePaths.withContentPaths(contentPaths);
return service.beginPurgeContent(resourceGroupName, profileName, endpointName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), contentFilePaths, this.client.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<Void>>>() {
@Override
public Observable<ServiceResponse<Void>> call(Response<ResponseBody> response) {
try {
ServiceResponse<Void> clientResponse = beginPurgeContentDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
Aggregations