A RESTful API Application built on Spring Framework. When running this application a command line runner will be excetuted in order to populate the in-memory SQL database with entries from a JSON file. The resource of RESTful API is People, which will response JSON structure data based on endpoints.
- Language: Java
- Development Kit: Java SDK 8
- Framework: Spring Framework
- Build Automation Tool: Apache Maven
- Database: H2 (In-Memory)
- ORM: Hibernate
- Unit Testing Framework: JUnit
- Service API: REST
- REST Testing Library: REST Assured
- IDE: IntelliJ IDEA (Ultimate Edition)
These instructions will get you a copy of the project up and running on you local machine for development and testing purposes.
- Java SDK 8
- Java IDE (IntelliJ IDEA recommended)
- Git
- Apache Maven
- Spring Boot
Note: If you want to use command line to run application and tests you need to install softwares mentioned in Optional above
Please follow carefully step by step instructions below in order to get the app up and running locally.
-
Open Terminal
-
Get a clone of this project in local machine:
git clone https://github.com/arianithetemi/spring-rest-app.git
cd spring-rest-app.git
-
Running application with IDE:
- Open this project folder with any Java IDE (IntelliJ IDEA recommended)
- Run the application using IDE Run Option
-
Running the application with Command line:
- Open Terminal
- Change Directory to the project directory in terminal
- Run the command below:
sudo mvn spring-boot:run
Note: After running the application please read the API documentation below the "Running Test Section"
For now there are three unit test cases for testing REST API. Follow the instructions below in order to run automated tests.
- Running tests with IDE:
- Run with any IDE the "RestappApplicationTests.java" file located in project location "spring-rest-app/src/test/com.arianit.restapp/".
- Running tests with command line:
- Open the Terminal
- Change directory to the project directory in terminal
- Run the command below:
sudo mvn test
Localhost base URL: http://localhost:8080
Note: In order to test API RESTful Endpoints you need to use an HTTP Client Tool, Postman is recommended
Returns json list of people data
-
URL
/api/people/
-
Method:
GET
-
Success Response:
-
Code: 200
Content:
[{ "id": 1, "name": "Keeley Bosco", "email": "[email protected]", "city": "Lake Gladysberg", "mac": "08:fd:0b:cd:77:f7", "timestamp": "2015-04-25 13:57:36 +0700", "creditcard": "1228-1221-1221-1431" }, {...}]
-
Returns json of a specific Person data based on its id
-
URL
/api/people/:id
-
URL Params
Required:
id=[integer]
-
Method:
GET
-
Success Response:
-
Code: 200
Content:
{ "id": 5, "name": "Dr. Araceli Lang", "email": "[email protected]", "city": "Yvettemouth", "mac": "9e:ea:28:41:2a:50", "timestamp": "2015-04-25 21:02:11 +0700", "creditcard": "1211-1221-1234-2201" }
-
Create new Person from json structure with values sent in body of request
-
URL
/api/people/
-
Method:
POST
-
Body Data (application/json)
{ "name": "John Doe", "email": "[email protected]", "city": "Gjilan", "mac": "9e:ea:28:41:2a:50", "creditcard": "1111-2222-3333-4444" }
-
Success Response:
-
Code: 200
Content:{ "id": 51, "name": "John Doe", "email": "[email protected]", "city": "Gjilan", "mac": "9e:ea:28:41:2a:50", "timestamp": "2018-02-27 20:24:32 675+0100", "creditcard": "1111-2222-3333-4444" }
-
Updates the values sent as json in request body of a specific Person by its ID, returns updated json Person structure
-
URL
/api/people/:id
-
Method:
PUT
-
URL Params
Required:
id=[integer]
-
Body Data (application/json)
{ "name": "John Doe", "email": "[email protected]", "city": "Prishtine" }
-
Success Response:
-
Code: 200
Content:{ "id": 5, "name": "John Doe", "email": "[email protected]", "city": "Prishtine", "mac": "9e:ea:28:41:2a:50", "timestamp": "2015-04-25 21:02:11 +0700", "creditcard": "1211-1221-1234-2201" }
-
Deletes Person by its ID and returns a message if deleted successfully
-
URL
/api/people/:id
-
Method:
DELETE
-
URL Params
Required:
id=[integer]
-
Success Response:
-
Code: 200
Content:
{"message": "Person successfully deleted!"}
-
Returns json of people data sorted naturally by its name
-
URL
/api/people/sort/name
-
Method:
GET
-
Success Response:
-
Code: 200
Content:
[{ "id": 32, "name": "Alec Howell", "email": "[email protected]", "city": "South Hollyport", "mac": "ca:8c:24:ef:65:98", "timestamp": "2015-04-25 00:38:05 +0700", "creditcard": "1234-2121-1221-1211" }, {...}]
-
If you want to see the database you need to access into the H2 Console DBMS Follow the instructions below:
- Run the application
- Go to http://localhost:8080/console
- In JDBC URL input write: jdbc:h2:mem:mydb;
- Click Connect and you have access to the data of in-memory database of this App
Note: The database is in-memory database so when restarting the application the new or modified data added in database will be removed!
- Arianit Hetemi