Package vertxval.httpclient
Class HttpClientModule
- java.lang.Object
-
- io.vertx.core.AbstractVerticle
-
- vertxval.VertxModule
-
- vertxval.httpclient.HttpClientModule
-
- All Implemented Interfaces:
io.vertx.core.Verticle
public abstract class HttpClientModule extends VertxModule
Module that exposes a set of functions to send different requests to a server. It's created from aHttpClientOptions
instance. It's just another verticle that needs to be deployed. You can create as many as you want, with different configurations:HttpClientOptions server1Options = new HttpClientOptions(); HttpClientOptions server2Options = new HttpClientOptions(); HttpClientModule httpServer1Module = new HttpClientModule(server1Options); HttpClientModule httpServer2Module = new HttpClientModule(server2Options); vertx.deployVerticle(httpServer1Module); vertx.deployVerticle(httpServer2Module);
get
,post
,put
,delete
and so on. You can create new verticles and expose them as functions of this module implementing the methodsdeployRequests()
anddefineRequests()
- See Also:
deployRequests()
,defineRequests()
-
-
Field Summary
Fields Modifier and Type Field Description λ<ConnectMessage,jsonvalues.JsObj>
connect
represents a CONNECT request.λ<DeleteMessage,jsonvalues.JsObj>
delete
represents a DELETE request.λ<GetMessage,jsonvalues.JsObj>
get
represents a GET request.λ<HeadMessage,jsonvalues.JsObj>
head
represents a HEAD request.λ<OptionsMessage,jsonvalues.JsObj>
options
represents a OPTIONS request.λ<PatchMessage,jsonvalues.JsObj>
patch
represents a PATCH request.λ<PostMessage,jsonvalues.JsObj>
post
represents a POST request.λ<PutMessage,jsonvalues.JsObj>
put
represents a PUT request.λ<TraceMessage,jsonvalues.JsObj>
trace
represents a TRACE request.-
Fields inherited from class vertxval.VertxModule
deployer, deploymentOptions
-
-
Constructor Summary
Constructors Constructor Description HttpClientModule(io.vertx.core.http.HttpClientOptions options)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
define()
override this method to initialize the instance fields of this class that represent the functions exposed by this module.protected abstract void
defineRequests()
method to initialize from the deployed verticles indeployRequests()
the functions that will be exposed by this module.protected void
deploy()
override this method and deploy the Verticles you want to be exposed by your module.protected abstract void
deployRequests()
method to deploy new verticles.-
Methods inherited from class vertxval.VertxModule
deployConsumer, deployConsumer, deployFn, deployFn, deployTask, deployTask, deployVerticle, deployλ, deployλ, getDeployedVerticle, start
-
-
-
-
Field Detail
-
get
public final λ<GetMessage,jsonvalues.JsObj> get
represents a GET request. It takes as input aGetMessage
instance and returns a response in a JsObj. The classResp
contains all the lenses and functions to get info from the response and manipulate it
-
post
public final λ<PostMessage,jsonvalues.JsObj> post
represents a POST request. It takes as input aPostMessage
instance and returns a response in a JsObj. The classResp
contains all the lenses and functions to get info from the response and manipulate it
-
put
public final λ<PutMessage,jsonvalues.JsObj> put
represents a PUT request. It takes as input aPutMessage
instance and returns a response in a JsObj. The classResp
contains all the lenses and functions to get info from the response and manipulate it
-
delete
public final λ<DeleteMessage,jsonvalues.JsObj> delete
represents a DELETE request. It takes as input aDeleteMessage
instance and returns a response in a JsObj. The classResp
contains all the lenses and functions to get info from the response and manipulate it
-
head
public final λ<HeadMessage,jsonvalues.JsObj> head
represents a HEAD request. It takes as input aHeadMessage
instance and returns a response in a JsObj. The classResp
contains all the lenses and functions to get info from the response and manipulate it
-
options
public final λ<OptionsMessage,jsonvalues.JsObj> options
represents a OPTIONS request. It takes as input aOptionsMessage
instance and returns a response in a JsObj. The classResp
contains all the lenses and functions to get info from the response and manipulate it
-
patch
public final λ<PatchMessage,jsonvalues.JsObj> patch
represents a PATCH request. It takes as input aPatchMessage
instance and returns a response in a JsObj. The classResp
contains all the lenses and functions to get info from the response and manipulate it
-
trace
public final λ<TraceMessage,jsonvalues.JsObj> trace
represents a TRACE request. It takes as input aTraceMessage
instance and returns a response in a JsObj. The classResp
contains all the lenses and functions to get info from the response and manipulate it
-
connect
public final λ<ConnectMessage,jsonvalues.JsObj> connect
represents a CONNECT request. It takes as input aConnectMessage
instance and returns a response in a JsObj. The classResp
contains all the lenses and functions to get info from the response and manipulate it
-
-
Method Detail
-
define
protected void define()
Description copied from class:VertxModule
override this method to initialize the instance fields of this class that represent the functions exposed by this module. TheVerticleRef
instances associated to the Verticles deployed in theVertxModule.deploy()
method can be gotten from their addresses with the methodVertxModule.getDeployedVerticle(String)
. A VerticleRef it's just a wrapper around a Verticle to interact with it. You can establish a dialogue with the Verticle using the methodVerticleRef.ask()
, which returns a function, or just send it messages without waiting for the response with the methodVerticleRef.tell()
, which returns a consumer. You may be interested in deploying Verticles on the fly to get a greater level of parallelism with the functionsDeployer.spawn(Function)
orDeployer.spawn(λ)
.private final String ADD_ONE_ADDRESS = "addOne"; private final String PRINT_ADDRESS = "print"; public static Function<Integer, Val<Integer>> triple; public static Function<Integer, Val<Integer>> addOne; public static Consumer<Integer> printNumber; protected void define(){ addOne = this.<Integer, Integer>getDeployedVerticle(ADD_ONE_ADDRESS).ask(); printNumber = this.<Integer, Void>getDeployedVerticle(PRINT_ADDRESS).tell(); //spawn returns a function that creates a verticle every time it's called. After the value is returned, the //the verticle is undeployed triple = deployer.spawnFn(i -> i * 3); }
- Specified by:
define
in classVertxModule
-
defineRequests
protected abstract void defineRequests()
method to initialize from the deployed verticles indeployRequests()
the functions that will be exposed by this module. You can create new functions spawning verticles as well with the methodDeployer.spawn(λ)
like in the following example:public λ<JsObj, JsObj> post_client; public λ<JsObj, JsObj> get_client; public λ<JsObj, JsObj> search; protected void defineRequests(){ // "create_client" was deployed in deployRequests method this.post_client = this.<JsObj, JsObj>getDeployedVerticle("create_client").ask(); // "get_client" was deployed in deployRequests method this.get_client = this.<String, JsObj>getDeployedVerticle("get_client").ask(); // define a λ that will spawn a new verticle every call this.search = deployer.spawnλ(term -> get.apply(new GetMessage().host("www.google.com") .uri("/search?q=" + term) ) ); }
- See Also:
deployRequests()
-
deploy
protected void deploy()
Description copied from class:VertxModule
override this method and deploy the Verticles you want to be exposed by your module. using the functionsVertxModule.deployFn(String, Function)
,VertxModule.deployλ(String, λ)
(String, Function)} orVertxModule.deployConsumer(String, Consumer)
. You can deploy tasks that will be executed when this module is deployed with the methodVertxModule.deployTask(Runnable)
. You can also deployed regular Verticles with the methodVertxModule.deployVerticle(AbstractVerticle)
- Specified by:
deploy
in classVertxModule
-
deployRequests
protected abstract void deployRequests()
method to deploy new verticles. You can just use the provided functions get, post, put etc exposed by the module and leave this method implementation empty. On the other hand you may be interested in creating new ones out of them. For example, to deploy two verticles listening on the addresses post_client and search:protected void deployRequests(){ λ<JsObj, JsObj> post_client = body -> post.apply(new PostMessage(body.serialize())); this.deployFn("post_client", post_customer ); λ<String, JsObj> get_client = id -> get.apply(new GetMessage().uri("/" + id)); this.deployFn("get_client", get_client ); }
- See Also:
defineRequests()
-
-