-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
URI template with Web Client example
- Loading branch information
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
web-client-examples/src/main/java/io/vertx/example/webclient/uritemplate/Client.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.vertx.example.webclient.uritemplate; | ||
|
||
import io.vertx.core.Future; | ||
import io.vertx.core.VerticleBase; | ||
import io.vertx.ext.web.client.WebClient; | ||
import io.vertx.launcher.application.VertxApplication; | ||
import io.vertx.uritemplate.UriTemplate; | ||
|
||
/* | ||
* @author <a href="mailto:[email protected]">Julien Viet</a> | ||
*/ | ||
public class Client extends VerticleBase { | ||
|
||
public static void main(String[] args) { | ||
VertxApplication.main(new String[]{Client.class.getName()}); | ||
} | ||
|
||
private static final UriTemplate REQUEST_URI = UriTemplate.of("/{?firstName}{&lastName}{&male}"); | ||
|
||
private WebClient client; | ||
|
||
@Override | ||
public Future<?> start() throws Exception { | ||
|
||
client = WebClient.create(vertx); | ||
|
||
return client.get(8080, "localhost", REQUEST_URI) | ||
.setTemplateParam("firstName", "Dale") | ||
.setTemplateParam("lastName", "Cooper") | ||
.setTemplateParam("male", "true") | ||
.send() | ||
.onSuccess(response -> System.out.println("Got HTTP response with status " + response.statusCode())); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
web-client-examples/src/main/java/io/vertx/example/webclient/uritemplate/Server.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.vertx.example.webclient.uritemplate; | ||
|
||
import io.vertx.core.Future; | ||
import io.vertx.core.VerticleBase; | ||
import io.vertx.launcher.application.VertxApplication; | ||
|
||
/* | ||
* @author <a href="mailto:[email protected]">Julien Viet</a> | ||
*/ | ||
public class Server extends VerticleBase { | ||
|
||
public static void main(String[] args) { | ||
VertxApplication.main(new String[]{Server.class.getName()}); | ||
System.out.println("Server started"); | ||
} | ||
|
||
@Override | ||
public Future<?> start() throws Exception { | ||
|
||
return vertx.createHttpServer().requestHandler(req -> { | ||
System.out.println("Got request with query params: " + req.query()); | ||
req.response().end(); | ||
}).listen(8080); | ||
} | ||
} |