DEV Community

NGUYEN THI HONG NHUNG
NGUYEN THI HONG NHUNG

Posted on

REST CRUD API

1. What are REST Services

-> A lightweight approach of communication between different apps
-> REST is language independent
-> REST works with any data format, but JSON is the most popular

2. JSON

  • An object:
{
   "name": value
}
Enter fullscreen mode Exit fullscreen mode
  • Names of the object's attributes are always in double quote, value is in double quote if it is a string

  • 4 HTTP methods: Post(Create), GET(Read), PUT(Update), DELETE(delete)

3. Spring Rest Controller

Development process:

  1. Add Maven dependency for Spring Boot starter web
  2. Create Spring Rest Service using @RestController (manually), instead you can use Rest's auto configuration, see in section 6

4. API Desgin Process

  1. Review API's requirements
  2. Identify main entity/resource
  3. Use Http methods to assign action on resource

5. Spring JPA

Automatically give CRUD operations on entities

  1. Extend JPARepository interface and plug in your entity and primary key
  2. Use your repository

6. Spring Data Rest

You only need to add spring-boot-starter-data-rest dependency to your pom.xml file, Spring will give REST CRUD operations

Top comments (0)