Class 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 a HttpClientOptions 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);
     
     
    Once deployed, you can use the defined functions get, post, put, delete and so on. You can create new verticles and expose them as functions of this module implementing the methods deployRequests() and defineRequests()
    See Also:
    deployRequests(), defineRequests()
    • Field Detail

      • get

        public λ<GetMessage,​jsonvalues.JsObj> get
        represents a GET request. It takes as input a GetMessage instance and returns a response in a JsObj. The class Resp 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 a PostMessage instance and returns a response in a JsObj. The class Resp 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 a PutMessage instance and returns a response in a JsObj. The class Resp 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 a DeleteMessage instance and returns a response in a JsObj. The class Resp 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 a HeadMessage instance and returns a response in a JsObj. The class Resp 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 a OptionsMessage instance and returns a response in a JsObj. The class Resp 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 a PatchMessage instance and returns a response in a JsObj. The class Resp 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 a TraceMessage instance and returns a response in a JsObj. The class Resp 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 a ConnectMessage instance and returns a response in a JsObj. The class Resp contains all the lenses and functions to get info from the response and manipulate it
    • Constructor Detail

      • HttpClientModule

        public HttpClientModule​(io.vertx.core.http.HttpClientOptions options)
    • 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 class VertxModule
      • defineRequests

        protected abstract void defineRequests()
        method to initialize from the deployed verticles in deployRequests() the functions that will be exposed by this module. You can create new functions spawning verticles as well with the method Deployer.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()
      • 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()