├── .gitignore ├── README.md ├── pom.xml └── src ├── main └── java │ └── com │ └── techprimers │ └── vertx │ └── App.java └── test └── java └── com └── techprimers └── vertx └── AppTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .idea 3 | .vertx 4 | *.iml -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Restful WebServices using Vertx 2 | 3 | - `http://localhost:8091/hello` - accessible at this path for both GET and POST. 4 | - For POST, use 'Content-Type' as `application/json` for Vertx to route the Resource Handlers -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.techprimers.vertx 6 | vertx-example 7 | 1.0-SNAPSHOT 8 | 9 | 10 | 11 | org.apache.maven.plugins 12 | maven-compiler-plugin 13 | 14 | 1.8 15 | 1.8 16 | 17 | 18 | 19 | 20 | jar 21 | 22 | vertx-example 23 | http://maven.apache.org 24 | 25 | 26 | UTF-8 27 | 28 | 29 | 30 | 31 | 32 | io.vertx 33 | vertx-web 34 | 3.5.1 35 | 36 | 37 | 38 | junit 39 | junit 40 | 3.8.1 41 | test 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/main/java/com/techprimers/vertx/App.java: -------------------------------------------------------------------------------- 1 | package com.techprimers.vertx; 2 | 3 | import io.vertx.core.Vertx; 4 | import io.vertx.core.http.HttpServer; 5 | import io.vertx.core.http.HttpServerResponse; 6 | import io.vertx.ext.web.Route; 7 | import io.vertx.ext.web.Router; 8 | 9 | public class App { 10 | 11 | public static void main(String[] args) { 12 | 13 | 14 | Vertx vertx = Vertx.vertx(); 15 | 16 | HttpServer httpServer = vertx.createHttpServer(); 17 | 18 | Router router = Router.router(vertx); 19 | Route handler1 = router 20 | .get("/hello/:name") 21 | .handler(routingContext -> { 22 | String name = routingContext.request().getParam("name"); 23 | System.out.println("came to hello: " + name); 24 | HttpServerResponse response = routingContext.response(); 25 | response.setChunked(true); 26 | response.write("Hi " + name + "\n"); 27 | response.end(); 28 | }); 29 | Route handler2 = router 30 | .post("/hello") 31 | .consumes("*/json") 32 | .handler(routingContext -> { 33 | System.out.println("came to post"); 34 | HttpServerResponse response = routingContext.response(); 35 | response.setChunked(true); 36 | response.write("Hi TechPrimers from post\n"); 37 | response.end(); 38 | }); 39 | 40 | 41 | httpServer 42 | .requestHandler(router::accept) 43 | .listen(8091); 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/com/techprimers/vertx/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.techprimers.vertx; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase 12 | { 13 | /** 14 | * Create the test case 15 | * 16 | * @param testName name of the test case 17 | */ 18 | public AppTest( String testName ) 19 | { 20 | super( testName ); 21 | } 22 | 23 | /** 24 | * @return the suite of tests being tested 25 | */ 26 | public static Test suite() 27 | { 28 | return new TestSuite( AppTest.class ); 29 | } 30 | 31 | /** 32 | * Rigourous Test :-) 33 | */ 34 | public void testApp() 35 | { 36 | assertTrue( true ); 37 | } 38 | } 39 | --------------------------------------------------------------------------------