In this article we will cover
Building RESTful web service using spring.
Register developed service application to Eureka Server.
Auth-Service – RESTful application
In this application we will build authentication rest-endpoint (“/auth/login/authenticate). It will basically check userid/password is valid or not, depending on that response will be send back.
Note: For this demo application, for userid/password authentication we will check useriId==password if this is true success response will return else un-success response will be return.
Maven Dependencies
- AOP for loggin-aspect
- Config – to retrieve application config from config-server.
- Eureka-Server – to register this service application to eureka-server.
Application Config files:
bootstrap.yml
authservice.yml
Name of the application is important as it gets register to eureka-server. Also when we look into application build using ribbon, circuit-breaker it will be important.
There is standard eureka configuration defined like eureka-server URL, renewal-interval, instanceId.
Java Code
Start application
Execute below curl command for validating service end-point.
curl -H “Content-type:application/json” -X POST http://localhost:9092/auth/login/authenticate -d ‘{“loginId”:”123″, “password”:”123″}’
curl -H “Content-type:application/json” -X POST http://localhost:9092/auth/login/authenticate -d ‘{“loginId”:”123″, “password”:”1235″}’
As application is enabled for service-registry it will get register to eureka-server.
Cheers – Happy learning 🙂
Ketan Gote
Comments
Post a Comment