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()
The purpose of this method is to initialize the functions/consumers/suppliers defined in public fields of this class that will be exposed.protected abstract void
defineRequests()
method to initialize from the deployed verticles indeployRequests()
the functions that will be exposed by this module.protected void
deploy()
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 λ<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 λ<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 λ<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 λ<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 λ<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 λ<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 λ<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 λ<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 λ<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
The purpose of this method is to initialize the functions/consumers/suppliers defined in public fields of this class that will be exposed.- 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()
- 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()
-
-