Skip to content

A simple RESTful web service with Spring Boot, Java Persistence API (JPA) and Hibernate

License

Notifications You must be signed in to change notification settings

fajarvm/spring-rest-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RESTful Web Service

This is a simple demo of a RESTful web service with Spring Boot, Java Persistence API (JPA) and Hibernate.

Requirements

Software required to run, install and test this project:

  • Java 1.8
  • MySQL version 5 (or above)
  • (Optional) Postman version 7.0 (or above)

Configuration

Modify the properties in the configuration file according to your environment. Configuration file: src/main/resources/application.properties

spring.datasource.username=root <--- Change these to your MySQL username and password
spring.datasource.password=root

Running the server

To install, execute this command on the repository root directory:

mvn clean install

Note: make sure your MySQL instance is running. And then, to run the server:

mvn spring-boot:run

Upon start-up, the server creates a database called localhost_db, a table products and inserts some test entries into the table.

Testing the API

The Swagger UI REST API docs is included into this project and can be accessed via http://localhost:8080/api/ (it should redirect user to the Swagger UI API Docs page)

Available endpoints are:

Endpoint Method Description
/products/ GET List all products.
/products/ POST Add a product to the list. Requires a JSON body message.*
/products/{id} GET Get a product with the given ID.
/products/{id} PUT Update a product with the given ID. Requires a JSON body message.*

*Example of JSON body message:

{ 
    "name": "Keyboard", 
    "currentPrice": 25.50
}

The message can also have only one of the properties.

Postman collection

The REST API can also be tested using Postman. Start the Postman application and import the collection file provided here: tools/postman_collection.json. The collection named 'RESTful Web Service' will be visible to the left and the available endpoints are listed underneath.

About

A simple RESTful web service with Spring Boot, Java Persistence API (JPA) and Hibernate

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages