Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
16 views
7 pages
B 9
Spring
Uploaded by
tresbonarchitecte
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save b9 For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
16 views
7 pages
B 9
Spring
Uploaded by
tresbonarchitecte
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save b9 For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save b9 For Later
You are on page 1
/ 7
Search
Fullscreen
oartt2023 19:38, Intwoduction to Spring Data REST | Bacldung “ Introduction to Spring Data REST Essai httos //adsfreestarcom/? \Written by. baeldung (https //wwwlbaeldung.com/author/oae\dung) REST (https:// www baoldung.com/category/rest) Spring Data (https:// www.baeldung.com/category/persistence/spring-persistence/spring-data) roforonce Spring Data REST thttps://www:baoldung.com/tag/spring-data-rest) Get started with Spring Data JPA through the reference Learn Spring Data JPA course: >» CHECK OUT THE COURSE (/learn-spring-data-jpa-course) Explore the future of 3D Petar} ore tata ss ey hitpsslww-baeldung.com/spring-data-estintro weoart2023 19:38, Introduction to Spring Data REST | Baeldung a 5 (https /ads freestarcom/? utm_campaign-branding&iutm .medium-banner&utm_source-baeldung.com&utm. content-baeldung.incontent 2 1, Overview This article wil explain the basics of Spring Data REST (https //spring io/projects/spring-data-rest) and show how to use it to build a simple REST APL In general, Spring Data REST is built on top of the Spring Data project and makes it easy to build hypermedia~ driven REST web services that connect to Spring Data repositories - all using HAL as the driving hypermedia type. It takes away a lot of the manual work usually associated with such tasks and makes implementing basic CRUD functionality for web applications quite simple. 2. Maven Dependencies The following Maven dependencies are required for our simple application:
oO “
org.sprinefrarework.bost
spring-boot-starter
“
org.springfrarcwork.bootspring-boot-start rest
“
org.springtrarework.boot
spring-boot- start spac/artifectTa>
depandercy> “
con.h2datsbase cartifectIdn2
We decided to use Spring Boot for this example, but classic Spring will also work fine, We also chose to use the H2 embedded database in order to avoid any extra setup, but the example can be applied to any database, (https /ads freestarcom/? 3. Writing the Application ‘We will start by writing a domain object to represent a user of our website: hitpssvww-baeldung.com/spring-data-estintro anoartt2023 19:38, Introduction to Spring Data REST | Baeltung ay a Fait cass waster ( oO private Leng id; private String names Private string ena‘; 11 standard getters and setters Every user has a name and an email. as well as an automatically-generated id, Now we can write a simple repository eReposstoryRestRescurce(cotlectionfesourceRel = "users", ath = “userst) oO public ‘interface UserRenos‘tary extends PasingAneSortingRepositary
{ Listewebsizeuser> FindyWame(eParan("nane") String ane); ‘This is an interface that allows you to perform various operations with WebsiteUser objects. We also defined a custom query that wil provide a lst of users based on a given name. ‘The @RepositoryRestResource annotation is optional and is used to customize the REST endpoint. we decided to ‘omit it, Spring would automatically create an endpoint at" AwebsiteUsers’ instead of */users. Finally. we will write a standard Spring Boot main class to initialize the application: > fs ete enn intos//adsteestarcom/? pubic ease Sprites cater ¢ i public static vote mein(Stringl) args) ( Springapplicatton.run(Springbacakestapplication.class, args); } Thats it! We now have a fully-functional REST API Let's take a look at tin action 4. Accessing the REST API If we run the application and go to hitp://Localhost 8080/ (http: //Localhost 8080/) in a browser, we will receive the following JSON htipsitwnww.bacldung.comlspring-data-restinto anoartt2023 19:38, Introduction to Spring Data REST | Baeltung ks: “ oO users”: { ef": shtp://localhost:8080/users{?page,stze,sert}", "templated? + true h "profite” + ( Inree™ + "https //ecalhost 800 /profi le” > y y Asyou can see, there isa */users’ endpoint available, and it already has the “2oage’."?size" and *?sorf options. ‘There is also a standard */profie’ endpoint, which provides application metadata. tis important to note that the response is structured in a way that follows the constraints of the REST architecture style, Specifically il provides a Uniform interface and self-descriptive messages, This means that each message contains enough information to describe how to process the message. There are no users in our application yet, so going to http //tocathost 8080/users thttp//localhost 8080/users) ‘would just show an emply list of users. Lets use curl to add a user crane" + Neest, ‘eestdtest con", « ‘ ret : "http: //locathost:8688/users/2" » Mhebsiteuser" = ( ef" + "http: //lecalhest:080/users/2" ? 3 3 Lets take a look at the response headers as well ‘You willnotice that the returned content types “application /halyisort: HAL {http /stateless.co/hal_specificationhtm) is a simple format that gives a consistent and easy way to hyperlink between resources in your APL. The header also automatically contains the Location header, which is the address ‘we can use to access the newly created user We can now access this user at http://Localhost 8080 /users/1(http:/localhost 8080/users/1) htipsitwnww.bacldung.comlspring-data-restinto anoartt2023 19:38, Introduction to Spring Data REST | Baeltung “ oO name" + Neest, sonait" + "testdtest.con", oMeket 2 ‘ + Yhttp://Locathost:8080/users/2" 1 Ynttp://lecathest:6080/users/2" ‘You can also use curl or any other REST client to issue PUT, PATCH, and DELETE requests. It also is important to note that Spring Data REST automatically follows the principles of HATEOAS. HATEOAS {https:/spring.io/projects/spring-hateoas) is one of the constraints of the REST architecture style, and it means that hypertext should be used to find your way through the API Finally. lets try to access the custom query that we wrate earlier and find all users with the name ‘test’. This is done by going to http://Locathost 8080 /users/search/findByName?name-test {http //localhost8080/users/search/fndByName?name-test) © ct 0 ) v cs wutedar 2 salt: ret": *http://locathost:8089/users/search/ Findbysane?nane=test” 5. Conclusion ‘This tutorial demonstrated the basics of creating a simple REST API with Spring Data REST. The example used in this article can be found in the linked GitHub project {https./githulscom/eugenp/tutorials/lree/master/persistence-modules/spring-data-restl Get started with Spring 5 and Spring Boot 2, through the Learn Spring course: >> CHECK OUT THE COURSE (/1s-course-ond) htipsitwnww.bacldung.comlspring-data-restinto sroart2023 19:38 Introduction to Spring Data REST | Baelung Learning to build your API with Spring? Download the E-book (/rest-api-spring-guide) Comments are closed on this article! ‘couRSES SERIES JACKSON JSON TUTORIAL /3HCxSON) SPRING PERSISTENCE TUTORIAL V/PERSISTENCS.A/THSPAING-SERIES) ‘ABOUT htipsitwnww.bacldung.comlspring-data-restintooavta023 1038 Taerusacci vrata anel? htipsitwnww.bacldung.comlspring-data-restinto Introduction to Spring Data REST | Baeltung W
You might also like
Spring RESTFull
PDF
No ratings yet
Spring RESTFull
44 pages
Labereco
PDF
No ratings yet
Labereco
44 pages
REST API With Spring Boot
PDF
No ratings yet
REST API With Spring Boot
5 pages
REST API Development
PDF
No ratings yet
REST API Development
9 pages
API & Ms Unit5
PDF
No ratings yet
API & Ms Unit5
20 pages
Spring, SpringBoot, JPA, Security, Hibernate - Zero To Master
PDF
No ratings yet
Spring, SpringBoot, JPA, Security, Hibernate - Zero To Master
182 pages
Student Controller
PDF
No ratings yet
Student Controller
24 pages
Spring Boot
PDF
No ratings yet
Spring Boot
6 pages
Quick Introduction To RESTful APIs
PDF
100% (1)
Quick Introduction To RESTful APIs
16 pages
REST With Spring Tutorial - Baeldung
PDF
No ratings yet
REST With Spring Tutorial - Baeldung
6 pages
Rest API Example
PDF
No ratings yet
Rest API Example
30 pages
Spring Rest: Spring Rest Is A Practical Guide For Designing and Developing Restful Apis Using The
PDF
No ratings yet
Spring Rest: Spring Rest Is A Practical Guide For Designing and Developing Restful Apis Using The
1 page
Spring Boot
PDF
No ratings yet
Spring Boot
19 pages
Restful Crud API
PDF
No ratings yet
Restful Crud API
26 pages
01 Spring Rest
PDF
No ratings yet
01 Spring Rest
15 pages
Complete Backed Course
PDF
No ratings yet
Complete Backed Course
32 pages
B 2
PDF
No ratings yet
B 2
8 pages
Chapter 1 Spring Boot Intro and Installation and Demo Project Day 2 - Google Docs
PDF
No ratings yet
Chapter 1 Spring Boot Intro and Installation and Demo Project Day 2 - Google Docs
20 pages
Practicle 8 To 10
PDF
No ratings yet
Practicle 8 To 10
10 pages
Unit-5 Spring Boot
PDF
No ratings yet
Unit-5 Spring Boot
48 pages
Unit 5
PDF
No ratings yet
Unit 5
41 pages
Tutorial 10
PDF
No ratings yet
Tutorial 10
9 pages
Spring Farmework
PDF
No ratings yet
Spring Farmework
7 pages
Build A Restful App With Spring MVC and Angularjs
PDF
No ratings yet
Build A Restful App With Spring MVC and Angularjs
161 pages
Day 36 (Java DUO) .PDF - ZJPQMG
PDF
No ratings yet
Day 36 (Java DUO) .PDF - ZJPQMG
22 pages
Building A REST API With Spring PDF
PDF
No ratings yet
Building A REST API With Spring PDF
118 pages
Documentation PDF
PDF
No ratings yet
Documentation PDF
13 pages
5 Unit5 Part2
PDF
No ratings yet
5 Unit5 Part2
32 pages
Web Frameworks QB
PDF
No ratings yet
Web Frameworks QB
8 pages
Build Your API With Spring
PDF
No ratings yet
Build Your API With Spring
106 pages
API Spring 1746607057
PDF
No ratings yet
API Spring 1746607057
118 pages
Building A CRUD RESTful API - Web Service With Spring Boot - by Gabriel Pulga - The Startup - Medium
PDF
No ratings yet
Building A CRUD RESTful API - Web Service With Spring Boot - by Gabriel Pulga - The Startup - Medium
16 pages
V10843
PDF
No ratings yet
V10843
13 pages
Unit-5
PDF
No ratings yet
Unit-5
194 pages
RestfulQB Mphasis s3
PDF
No ratings yet
RestfulQB Mphasis s3
20 pages
Session01 - APIs & Spring Core
PDF
No ratings yet
Session01 - APIs & Spring Core
33 pages
Spring MVC
PDF
No ratings yet
Spring MVC
86 pages
Adding Role Based Security With Spring Boot REST APIs
PDF
No ratings yet
Adding Role Based Security With Spring Boot REST APIs
18 pages
NaanMudhalvan FullStack-1
PDF
No ratings yet
NaanMudhalvan FullStack-1
5 pages
Spring Boot & Microservices - Day3
PDF
No ratings yet
Spring Boot & Microservices - Day3
11 pages
Spring Boot Using Rest API
PDF
No ratings yet
Spring Boot Using Rest API
32 pages
Lab9 - Building A Basic CRUD RESTful Spring Boot MVC Application
PDF
No ratings yet
Lab9 - Building A Basic CRUD RESTful Spring Boot MVC Application
11 pages
Building A REST API With Spring
PDF
No ratings yet
Building A REST API With Spring
118 pages
Building A REST API With Spring
PDF
No ratings yet
Building A REST API With Spring
118 pages
REST With Jersy Cheetsheet
PDF
No ratings yet
REST With Jersy Cheetsheet
9 pages
Spring RestTemplate - With Examples
PDF
No ratings yet
Spring RestTemplate - With Examples
6 pages
Building A RESTful Web Service
PDF
No ratings yet
Building A RESTful Web Service
8 pages
Learn Spring v1.5
PDF
No ratings yet
Learn Spring v1.5
116 pages
Spring Boot Master Class
PDF
No ratings yet
Spring Boot Master Class
3 pages
Spring Framework and Spring Boot (5 Days)
PDF
100% (1)
Spring Framework and Spring Boot (5 Days)
5 pages
Spring Boot Rest API
PDF
No ratings yet
Spring Boot Rest API
91 pages
Spring MVC Cookbook - Sample Chapter
PDF
No ratings yet
Spring MVC Cookbook - Sample Chapter
47 pages
B 5
PDF
No ratings yet
B 5
6 pages
Building Rest Api12345 Presentation
PDF
No ratings yet
Building Rest Api12345 Presentation
22 pages
Online Banking Rest A Pi
PDF
No ratings yet
Online Banking Rest A Pi
44 pages
Spring Boot, MySQL, JPA, Hibernate Restful CRUD API Tutorial
PDF
No ratings yet
Spring Boot, MySQL, JPA, Hibernate Restful CRUD API Tutorial
15 pages
SpringBOOT Web MVC Handnote
PDF
No ratings yet
SpringBOOT Web MVC Handnote
10 pages
Unit 5 (API)
PDF
No ratings yet
Unit 5 (API)
35 pages
Z 31
PDF
No ratings yet
Z 31
7 pages
Z 32
PDF
No ratings yet
Z 32
9 pages
Z34
PDF
No ratings yet
Z34
7 pages
Z 26
PDF
No ratings yet
Z 26
7 pages
Z 19
PDF
No ratings yet
Z 19
6 pages
Z 12
PDF
No ratings yet
Z 12
10 pages
Z 30
PDF
No ratings yet
Z 30
7 pages
Z 24
PDF
No ratings yet
Z 24
7 pages
Z 27
PDF
No ratings yet
Z 27
7 pages
Z 18
PDF
No ratings yet
Z 18
7 pages
Z 14
PDF
No ratings yet
Z 14
9 pages
Z 9
PDF
No ratings yet
Z 9
8 pages
Z 17
PDF
No ratings yet
Z 17
7 pages
Z 16
PDF
No ratings yet
Z 16
6 pages
Sa
PDF
No ratings yet
Sa
8 pages
B 8
PDF
No ratings yet
B 8
6 pages
X 3
PDF
No ratings yet
X 3
5 pages
B 1
PDF
No ratings yet
B 1
9 pages
S 8
PDF
No ratings yet
S 8
7 pages
P 16
PDF
No ratings yet
P 16
19 pages
S 6
PDF
No ratings yet
S 6
11 pages
S 4
PDF
No ratings yet
S 4
8 pages
B 2
PDF
No ratings yet
B 2
12 pages
P 18
PDF
No ratings yet
P 18
11 pages
S 3
PDF
No ratings yet
S 3
12 pages
B 3
PDF
No ratings yet
B 3
12 pages
B 5
PDF
No ratings yet
B 5
12 pages
P 14
PDF
No ratings yet
P 14
11 pages