Skip to content

Commit

Permalink
Add @ClientFormParam to Reactive REST Client
Browse files Browse the repository at this point in the history
  • Loading branch information
Eng-Fouad committed Jul 5, 2023
1 parent 8a06248 commit c15f337
Show file tree
Hide file tree
Showing 12 changed files with 722 additions and 71 deletions.
77 changes: 76 additions & 1 deletion docs/src/main/asciidoc/rest-client-reactive.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,82 @@ Note that if an interface method contains an argument annotated with `@QueryPara
priority over anything specified in any `@ClientQueryParam` annotation.
====

More information about this annotation can be found on the javadoc of
More information about this annotation can be found on the javadoc of link:https://javadoc.io/doc/io.quarkus/quarkus-rest-client-reactive/latest/io/quarkus/rest/client/reactive/ClientQueryParam.html[`@ClientQueryParam`].

=== Form Parameters

Form parameters can be specified using `@RestForm` (or `@FormParam`) annotations:

[source, java]
----
package org.acme.rest.client;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
import org.jboss.resteasy.reactive.RestForm;
import jakarta.ws.rs.PORT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.FormParam;
import jakarta.ws.rs.core.MultivaluedMap;
import java.util.Map;
import java.util.Set;
@Path("/extensions")
@RegisterRestClient(configKey = "extensions-api")
public interface ExtensionsService {
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
Set<Extension> postId(@FormParam("id") Integer id);
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
Set<Extension> postName(@RestForm String name);
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
Set<Extension> postFilter(@RestForm Map<String, String> filter);
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
Set<Extension> postFilters(@RestForm MultivaluedMap<String, String> filters);
}
----

==== Using @ClientFormParam

Form parameters can also be specified using `@ClientFormParam`, similar to `@ClientQueryParam`:

[source, java]
----
@ClientFormParam(name = "my-param", value = "${my.property-value}")
public interface Client {
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
String postWithParam();
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@ClientFormParam(name = "some-other-param", value = "other")
String postWithOtherParam();
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@ClientFormParam(name = "param-from-method", value = "{with-param}")
String postFromMethod();
default String withParam(String name) {
if ("param-from-method".equals(name)) {
return "test";
}
throw new IllegalArgumentException();
}
}
----

More information about this annotation can be found on the javadoc of link:https://javadoc.io/doc/io.quarkus/quarkus-rest-client-reactive/latest/io/quarkus/rest/client/reactive/ClientFormParam.html[`@ClientFormParam`].

=== Path Parameters

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ void forClass(MethodCreator ctor, AssignableResultHandle globalTarget,
* Called when a {@link jakarta.ws.rs.client.WebTarget} has been populated for a normal Client
*/
void forWebTarget(MethodCreator methodCreator, IndexView index, ClassInfo interfaceClass, MethodInfo method,
AssignableResultHandle webTarget, BuildProducer<GeneratedClassBuildItem> generatedClasses);
AssignableResultHandle webTarget, BuildProducer<GeneratedClassBuildItem> generatedClasses,
AssignableResultHandle formValues);

/**
* Called when a {@link jakarta.ws.rs.client.WebTarget} has been populated for a sub Client
*/
void forSubResourceWebTarget(MethodCreator methodCreator, IndexView index, ClassInfo rootInterfaceClass,
ClassInfo subInterfaceClass,
MethodInfo rootMethod, MethodInfo subMethod, AssignableResultHandle webTarget,
BuildProducer<GeneratedClassBuildItem> generatedClasses);
BuildProducer<GeneratedClassBuildItem> generatedClasses, AssignableResultHandle formValues);

/**
* Method-level alterations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ A more full example of generated client (with sub-resource) can is at the bottom
for (JaxrsClientReactiveEnricherBuildItem enricher : enrichers) {
enricher.getEnricher()
.forWebTarget(methodCreator, index, interfaceClass, jandexMethod, methodTarget,
generatedClasses);
generatedClasses, formParams);
}

AssignableResultHandle builder = methodCreator.createVariable(Invocation.Builder.class);
Expand Down Expand Up @@ -1659,7 +1659,7 @@ private void handleSubResourceMethod(List<JaxrsClientReactiveEnricherBuildItem>
for (JaxrsClientReactiveEnricherBuildItem enricher : enrichers) {
enricher.getEnricher()
.forSubResourceWebTarget(subMethodCreator, index, interfaceClass, subInterface,
jandexMethod, jandexSubMethod, methodTarget, generatedClasses);
jandexMethod, jandexSubMethod, methodTarget, generatedClasses, formParams);
}

AssignableResultHandle builder = subMethodCreator.createVariable(Invocation.Builder.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.jboss.jandex.DotName;

import io.quarkus.rest.client.reactive.ClientExceptionMapper;
import io.quarkus.rest.client.reactive.ClientFormParam;
import io.quarkus.rest.client.reactive.ClientFormParams;
import io.quarkus.rest.client.reactive.ClientQueryParam;
import io.quarkus.rest.client.reactive.ClientQueryParams;
import io.quarkus.rest.client.reactive.ClientRedirectHandler;
Expand All @@ -27,6 +29,8 @@ public class DotNames {

public static final DotName CLIENT_QUERY_PARAM = DotName.createSimple(ClientQueryParam.class.getName());
public static final DotName CLIENT_QUERY_PARAMS = DotName.createSimple(ClientQueryParams.class.getName());
public static final DotName CLIENT_FORM_PARAM = DotName.createSimple(ClientFormParam.class.getName());
public static final DotName CLIENT_FORM_PARAMS = DotName.createSimple(ClientFormParams.class.getName());
public static final DotName REGISTER_CLIENT_HEADERS = DotName.createSimple(RegisterClientHeaders.class.getName());
public static final DotName CLIENT_REQUEST_FILTER = DotName.createSimple(ClientRequestFilter.class.getName());
public static final DotName CLIENT_RESPONSE_FILTER = DotName.createSimple(ClientResponseFilter.class.getName());
Expand Down
Loading

0 comments on commit c15f337

Please sign in to comment.