private static String extractPath(Element element) throws NoAnnotationException { GET getAnnotation = element.getAnnotation(GET.class); if (getAnnotation != null) { return getAnnotation.value(); } POST postAnnotation = element.getAnnotation(POST.class); if (postAnnotation != null) { return postAnnotation.value(); } DELETE deleteAnnotation = element.getAnnotation(DELETE.class); if (deleteAnnotation != null) { return deleteAnnotation.value(); } PUT putAnnotation = element.getAnnotation(PUT.class); if (putAnnotation != null) { return putAnnotation.value(); } throw new NoAnnotationException(); }
private void parseMethodAnnotation(Annotation annotation) { if (annotation instanceof DELETE) { parseHttpMethodAndPath("DELETE", ((DELETE) annotation).value(), false); } else if (annotation instanceof GET) { parseHttpMethodAndPath("GET", ((GET) annotation).value(), false); } else if (annotation instanceof HEAD) { parseHttpMethodAndPath("HEAD", ((HEAD) annotation).value(), false); if (!Void.class.equals(responseType)) { throw methodError("HEAD method must use Void as response type."); } } else if (annotation instanceof PATCH) { parseHttpMethodAndPath("PATCH", ((PATCH) annotation).value(), true); } else if (annotation instanceof POST) { parseHttpMethodAndPath("POST", ((POST) annotation).value(), true); } else if (annotation instanceof PUT) { parseHttpMethodAndPath("PUT", ((PUT) annotation).value(), true); } else if (annotation instanceof OPTIONS) { parseHttpMethodAndPath("OPTIONS", ((OPTIONS) annotation).value(), false); } else if (annotation instanceof HTTP) { HTTP http = (HTTP) annotation; parseHttpMethodAndPath(http.method(), http.path(), http.hasBody()); } else if (annotation instanceof retrofit2.http.Headers) { String[] headersToParse = ((retrofit2.http.Headers) annotation).value(); if (headersToParse.length == 0) { throw methodError("@Headers annotation is empty."); } headers = parseHeaders(headersToParse); } else if (annotation instanceof Multipart) { if (isFormEncoded) { throw methodError("Only one encoding annotation is allowed."); } isMultipart = true; } else if (annotation instanceof FormUrlEncoded) { if (isMultipart) { throw methodError("Only one encoding annotation is allowed."); } isFormEncoded = true; } }
@Test public void delete() { class Example { @DELETE("/foo/bar/") // Call<ResponseBody> method() { return null; } } Request request = buildRequest(Example.class); assertThat(request.method()).isEqualTo("DELETE"); assertThat(request.headers().size()).isZero(); assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/"); assertNull(request.body()); }
@Test public void contentTypeAnnotationHeaderAddsHeaderWithNoBody() { class Example { @DELETE("/") // @Headers("Content-Type: text/not-plain") // Call<ResponseBody> method() { return null; } } Request request = buildRequest(Example.class); assertThat(request.headers().get("Content-Type")).isEqualTo("text/not-plain"); }
@DELETE("/users/{username}/collection/folders/1/releases/{release_id}/instances/{instance_id}") Single<Response<Void>> removeFromCollection(@Path("username") String username, @Path("release_id") String releaseId, @Path("instance_id") String instanceId);
@DELETE("/users/{username}/wants/{release_id}") Single<Response<Void>> removeFromWantlist(@Path("username") String username, @Path("release_id") String releaseId);
@Headers({HEADER_API_VERSION}) @DELETE("customer/address") Observable<BaseJson<String>> deleteAddress(@Query("id") int id);
@DELETE("/api/csars/{csarName}/delete") Call<ResponseBody> deleteCsar( @Path("csarName") String name );
@DELETE("/api/csars/{csarName}/transformations/{platform}/delete") Call<ResponseBody> deleteTransformation( @Path("csarName") String csarName, @Path("platform") String platform );
@DELETE("/v1/shots/{shot_id}/like") Observable<Response<ShotLike>> unlikeShot(@Path("shot_id") long shotId);
@DELETE("/v1/users/{user_id}/follow") Observable<Response<Body>> unfollow(@Path("user_id") long userId);
@DELETE("{handle}") Call<ResponseBody> delete( @Path("handle") String handle, @Query("key") String key, @Query("policy") String policy, @Query("signature") String signature);
@DELETE("photos/{id}/like") Flowable<Response<LikeResult>> unlike(@Path("id") String id);
@DELETE("collections/{id}") Flowable<DeleteCollectionResult> deleteCollection(@Path("id") int id);
@DELETE("collections/{collection_id}/remove") Flowable<ChangeCollectionPhotoResult> deletePhotoFromCollection(@Path("collection_id") int collection_id, @Query("photo_id") String photo_id);
@FormUrlEncoded @DELETE() Observable<ResponseBody> delete(@Url() String url, @FieldMap Map<String, String> maps);
@DELETE() Observable<ResponseBody> delete(@Url() String url, @QueryMap Map<String, String> maps);
@DELETE() Observable<ResponseBody> delete(@Url String url, @QueryMap Map<String, String> maps);
/** * { "status": 0, "msg": "success" } */ @DELETE("reqfilter/{iconpack}/{user}") Call<ResResBean> undoFilterPkg(@Path("iconpack") String iconPack, @Path("user") String user, @Query("pkg") String pkgName, @Query("launcher") String launcherActivity);
@DELETE("keys/{key}") Call<Boolean> delete(@Path("key") String key, @Query("session") long session, @Query("version") long version);
@DELETE("/consumers/{consumer_id}/oauth2/{id}") Call<Void> deleteConsumerApplication(@Path("consumer_id") String consumerId, @Path("id") String applicationId);
@DELETE("/oauth2_tokens/{id}") Call<Token> deleteToken(@Path("id") String tokenId);
@DELETE("/apis/{api}/plugins/{id}") Call<Void> deletePluginForApi(@Path("api") String apiNameOrId, @Path("id") String pluginNameOrId);
@DELETE("user/following/{user}") Call<Void> unfollow(@Header("Authorization") String credentials, @Path("user") String user);
@DELETE Call<String> delete(@Url String url, @QueryMap Map<String, Object> params);
@Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.appservice.WebApps deleteFunctionKey" }) @DELETE("admin/functions/{name}/keys/{keyName}") Observable<Void> deleteFunctionKey(@Path("name") String functionName, @Path("keyName") String keyName);
@DELETE("project/deleteSelectedProject/") public Call<Position> deleteSelectedProject(@Query("projectIdentifier") int projectIdentifier);
@DELETE("animelist/{anime_id}") Call<Object> deleteAnime(@Path("anime_id") int id);
@DELETE("mangalist/{manga_id}") Call<Object> deleteManga(@Path("manga_id") int id);
@DELETE("records/{record_id}") Call<Void> deleteRecord(@Header("Authorization") String token, @Path("record_id") String id);
@DELETE Observable<String> delete(@Url String url, @QueryMap Map<String, Object> params, @HeaderMap Map<String, Object> header);
@NonNull @DELETE("repos/{login}/{repoId}") Single<Response<Boolean>> deleteRepo(@Path("login") String login, @Path("repoId") String repoId);
@NonNull @DELETE("user/starred/{owner}/{repo}") Single<Response<Boolean>> unstarRepo(@NonNull @Path("owner") String login, @NonNull @Path("repo") String repoId);
@NonNull @DELETE("user/subscriptions/{owner}/{repo}") Single<Response<Boolean>> unwatchRepo(@Path("owner") String owner, @Path("repo") String repo);
@NonNull @DELETE("repos/{owner}/{repo}/comments/{id}") Single<Response<Boolean>> deleteComment(@Path("owner") String owner, @Path("repo") String repo, @Path("id") long id);
@DELETE("user/following/{username}") Single<Response<Boolean>> unfollowUser(@Path("username") @NonNull String username);
@DELETE("repos/{owner}/{repo}/issues/{number}/lock") Single<Response<Boolean>> unlockIssue(@Path("owner") String owner, @Path("repo") String repo, @Path("number") int number);