Develop a web application with one endpoint, eg GET http://localhost:8080/users
This backend version of the User API application only provides a REST API. There is no UI.
git clone https://github.com/harinathk/user-api-rest.git
cd user-api-rest
./mvnw spring-boot:run
In its default configuration, User API uses an in-memory database (H2) which gets populated at startup with data. A similar setups is provided for MySql in case a persistent database configuration is needed. To run user api locally using persistent database, it is needed to change profile defined in application.properties file.
For MySQL database, it is needed to change param "h2db" to "mysql" in string
spring.profiles.active=h2db
defined in application.properties file.
Before do this, would be good to check properties defined in application-mysql.properties file.
spring.datasource.url = jdbc:mysql://localhost:3306/users?useUnicode=true
spring.datasource.username=ua
spring.datasource.password=userapi
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.database=MYSQL
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
spring.jpa.hibernate.ddl-auto=none
GET http://localhost:8080/users/salary?from=0&to=4000
{
"results": [
{
"name": "Isabella",
"salary": 1731.0
},
{
"name": "Tyler",
"salary": 891.0
},
{
"name": "Jacob",
"salary": 2607.0
},
{
"name": "Lenny",
"salary": 4000.0
},
{
"name": "Aida",
"salary": 698.0
},
{
"name": "Chelsea",
"salary": 3589.0
}
]
}
ErrorResponse, if there are no users within salary range
{
"code": "204",
"message": "Users Not Found",
"details": "uri=/users"
}
GET http://localhost:8080/users
GET http://localhost:8080/users/1
GET http://localhost:8080/users/salary?from=0&to=4000
GET http://localhost:8080/users/100