Heim  >  Artikel  >  Java  >  REST-CRUD-API

REST-CRUD-API

PHPz
PHPzOriginal
2024-09-03 17:10:02488Durchsuche

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
}
  • 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

Das obige ist der detaillierte Inhalt vonREST-CRUD-API. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn