Skip to content

alperenasln/spring-restfulapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RESTFUL API by using Spring boot and Heroku

1) Starting with Spring boot

From https://start.spring.io, as a Maven project, Spring boot 2.4.4,Java version 8. I added 3 dependencies(Web,JPA and H2) to Spring boot and downloaded JAR file.

2) Opening JAR in Eclipse

I imported JAR file as Existing Maven Project and created new project.

3) Designing RESTFUL API

I started create my object USER firstly.Initialized private ID and public name .Then overrided equals,hash,toString methods. Then wrote UserController where we use CRUD operations.

image

Then wrote LoadDatabase to configurate logs and database. And interface of UserRepository. Lastly created an exception handling of "user not found" and wrote HTTPStatus to give a exception message in a different class(UserNotFoundAdvice.java). We've done with coding. Run this code on to start server and check from http://localhost:8080/users/

4) Testing on Postman

Created a collection then; used GET request on http://localhost:8080/users/ URL. used PUT request to add new user:

put

used POST request to update user:

post

used DELETE request to delete user

delete

used GET request to check users.

getafterdelete

5) Uploading code on Github

Uploaded my whole Java code to Github. By https://www.youtube.com/watch?v=nHk53YnrE5k

6) Deploying Heroku

I connected my Heroku account to Github. Then deploy manually and choose main branch. But I got error with Java version. So I went back to my code and changed java version from 15 to 1.8 on "pom.xml". Finally I deployed my code and get this link : https://spring-restfulapi-demo.herokuapp.com/users

Resources

I usually used REST tutorial of Spring from: https://spring.io/guides/tutorials/rest/

About

CRUD Restful API with Spring boot

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages