Java resp-api project to study technologies such as REST, Spring Framework(MVC), Hibernate ORM, Junit5, Mockito, MockMvc, CI/CD and others.
Rest-api for "Project management tool" demo project. A simple project to do in one month and gain experience for larger projects. I have idea to made my own "Project management tool" to learn new technologies and track time I spent on solving "tasks".
Steps to make this project:
- Creating SQL commands for generating MySQL Schema
- Set up Spring MVC using Java-based Configuration
- Set up Data Source
- Set up Hibernate using Java-based Configuration
- Defining Entity with JPA and Hibernate
- Creating DAO layer with Hibernate implementation
- Creating Service layer
- Creating Spring MVC REST Controller layer
Additions:
- jdk: 11-amazon-corretto java version
- build tool: Maven
- framework: Spring Framework
- database: MySQL
- ORM: Hibernate ORM
- unit test: Junit5
- mocks: Mockito, MockMvc
- server: Tomcat embedded
install git
install JDK 11(amazon correto, openJDK)
install maven3+
install mysql workbench
Choose a directory for project, download project from github:
$ git clone https://github.com/vladkondratuk/pm-rest-api.git
Run terminal command in project directory:
$ cd pm-rest-api/
$ mvn clean install
Run terminal command in project directory:
$ cd /rest-app
$ mvn clean install cargo:run
Press Ctrl+C to stop app.
A REST API is an application program interface that uses HTTP requests to GET, PUT, POST and DELETE data.
Check RESTful api for more about RESTful api.
The HTTP verbs comprise a major portion of our “uniform interface” constraint and provide us the action counterpart to the noun-based resource. The primary or most-commonly-used HTTP verbs (or methods, as they are properly called) are POST, GET, PUT, and DELETE. These correspond to create, read, update, and delete (or CRUD) operations, respectively.
The HTTP GET method is used to retrieve (or read) a representation of a resource.
Examples:
GET http://localhost:8090/rest-api/projects
GET http://localhost:8090/rest-api/tasks/3
GET http://localhost:8090/rest-api/activities
GET http://localhost:8090/rest-api/activities/2
PUT is most-often utilized for update capabilities, PUT-ing to a known resource URI with the request body containing the newly-updated representation of the original resource.
Examples:
PUT http://localhost:8090/rest-api/projects/1
PUT http://localhost:8090/rest-api/tasks/3
The POST verb is most-often utilized for creation of new resources. In particular, it's used to create subordinate resources. That is, subordinate to some other (e.g. parent) resource. In other words, when creating a new resource, POST to the parent and the service takes care of associating the new resource with the parent, assigning an ID (new resource URI), etc.
Examples:
POST http://localhost:8090/rest-api/projects
POST http://localhost:8090/rest-api/tasks
DELETE is pretty easy to understand. It is used to delete a resource identified by a URI.
Examples:
DELETE http://localhost:8090/rest-api/projects/1
DELETE http://localhost:8090/rest-api/tasks/3
Install jq, is a command-line tool for parsing JSON.
$ curl GET -v http://localhost:8090/rest-api/projects | jq
Simple example data conversion from MySQL table to POJO and then to JSON.
CREATE TABLE `activity` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`activity_name` varchar(128) DEFAULT NULL,
PRIMARY KEY (`id`)
)
@Entity
@Table(name = "activity")
public class Activity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Column(name = "activity_name")
private String activityName;
//Constructors
//Getters and Setters
}
{
"id": 1,
"activityName": "activity example"
}
Produced by Vladiskav Kondratuk 2020