Skip to content

Create a Spring Boot Project To learn using annotations such as @repository, @service, @RestController, @GetMapping, @PostMapping, @DeleteMapping

Notifications You must be signed in to change notification settings

praxton74/SPRING-REST_API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

SPRING-API

This project is a simple Rest API with Spring Boot CRUD Appliacation.

How to Create a Spring Starter Project?

In Eclipse,

File -> New -> Spring Starter Project

as shown below.

new-starter-project-screen

Repository Package

After that, we're creating Repository classes. So let's learn @Repository annotation. @Repository annotation indicates that an annotated class is a "Repository", originally defined byDomain-Driven Design (Evans, 2003) as "a mechanism for encapsulating storage,retrieval, and search behavior which emulates a collection of objects". This project we're not using DataBase so we have two private variables that are studentList and courseList. They're our repository. We're implementing CRUD operations for the lists(studentList and courseList).

Service Package

Now, let's create Service classes. So, what is @Service annotation? @Service annotation is used with classes that provide some business functionalities. It indicates that an annotated class is a "Service", originally defined by Domain-DrivenDesign (Evans, 2003) as "an operation offered as an interface that stands alone in themodel, with no encapsulated state." This classes has variables. The variables' types are from repository package.

Controller Package

In this package, we use @RestController annotation. This annotation takes care of mapping request data to the defined request handler method. Once response body is generated from the handler method, it converts it to JSON or XML response.

We can use all HTTP Request with @Restcontroller. See StudentController.java.

Let's Run The Application and Test HTTP Requests

Note: I use Postman to send request.

  • Student in JSON Format:
{
    "id": 125,
    "studentName": "Arda",
    "courses":[
        {
            "courseName": "Math"
        }
    ]
}
  • Course in JSON Format:
{
    "courseName": "English"
}

1-Post Method

Endpoints:

post-method

2-Get Method

Endpoints:

get-method

3-Put Method

Endpoint:

update-method

4-Delete Method

Endpoints:

delete-method

You can test the other endpoints. You can also change the endpoints and make practise.

About

Create a Spring Boot Project To learn using annotations such as @repository, @service, @RestController, @GetMapping, @PostMapping, @DeleteMapping

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages