Application trying to demonstrate authentication, session management, public and protected APIs, vertx messaging capabilities and data handling using MongoDB, Vertx Reactivex and EventBus.
Git clone the project on your local machine and import it to your favorite ide.
For runnning this, you will need
- Java 1.8
- Gradle support - In Eclipse editor, goto help -> eclipse marketplace -> search for buildship (buildship gradle integration) and install it.
This application allows user to signup, send welcome email, activates user, authenticates user, manages the session for the user and allows authenticated user to create another user. It shows the usage of Public and Private APIs.
- AppLauncher -> The starting point of the application. It is used to set the app configuration.
- MainVerticle -> Main verticle deploys all the other verticles used in the program.
- Handlers -> Handlers are basically the controllers which receives the input, process the input and returns the Json response back to the user.
For running the app, (IDE used here is Eclipse)
- Open appConfig.json file and set the "http_server_port" as per your choice. Also, update the "mailConfig" settings as per your mail provider.
- Once, changes are done in appConfig.json, right click on the project("vertx-realworld-app"),
select "Run As" -> "Run Configurations". Set:- Main: io.vertx.realworld.AppLauncher
- Program arguments:
run io.vertx.realworld.verticle.MainVerticle -conf ../vertx-realworld-app/src/main/resources/appConfig.json - VM arguments: -Dlogback.configurationFile=file:../vertx-realworld-app/src/main/resources/logback.xml
After setting the variables, click "Run".
- If app starts successfully, goto http://localhost:8080/runner/api/ping. Status json {"code":200,"message":"success","hasError":false,"data":{"status":"OK"}} will be served as response.
- For signing-up the user, do
Type: POST http://localhost:8080/runner/api/user/signup
Headers: Content-Type: application/json
Data to send: json data below -> I have used mailinator here to receive the welcome email
{
"firstName": "Grey",
"lastName": "Seal",
"email": "[email protected]",
"password": "password"
}
Successful Response would be: A temporary link will be send back. However, this temporary link will also be part of the welcome email. You have to click "Activate Account" button
{
"code": 200,
"message": "success",
"hasError": false,
"data": {
"link": "http://localhost:8080/runner/api/link/c9f2f133a5b445368b23c4ff8cf71bef"
}
}
Alternatively, you can also Activate the account using API
- For activating the user, do
Type: GET http://http://localhost:8080/runner/api/link/{{unique_link_here_from_signup_response}}
Successful Response would be:
{
"code": 200,
"message": "success",
"hasError": false,
"data": {
"message": "Account has been activated successfully."
}
}
- After signing-up, time to authenticate the user, do
Type: POST http://localhost:8080/runner/api/session/authenticate
Headers: Content-Type: application/json
Data to send: json data below ->
{
"email": "[email protected]",
"password": "password"
}
Successful Response would be:
{
"code": 200,
"message": "success",
"hasError": false,
"data": {
"email": "[email protected]",
"firstName": "Grey",
"lastName": "Seal"
}
}
Response Headers on successful authentication:
Authorization BEARER c1d887063c3e492b9951b0479fadddda
CORRELATION-ID 5a619f45a2f14615a7ba4346
- For creating new users after authentication, do
Type: POST http://localhost:8080/runner/api/user
Headers: Content-Type: application/json; Authorization: BEARER c1d887063c3e492b9951b0479fadddda
Data to send: json data below ->
{
"firstName": "Vertx",
"lastName": "User",
"email": "[email protected]",
"password": "password"
}
Successful Response would be:
{
"code": 200,
"message": "success",
"hasError": false,
"data": {
"email": "[email protected]",
"firstName": "Sam",
"lastName": "Manuael"
}
}
Execute the below scripts to the mongo collections
db.app_users.createIndex( { "email": 1 }, { unique: true } )
db.sessions.createIndex( { "token": 1 }, { expireAfterSeconds: 86400 } )
db.temporary_links.createIndex( { "link": 1 }, { expireAfterSeconds: 86400 } )