Spring HATEOAS Rest API + JQuery Ajax POST/GET example | Spring Boot

https://grokonez.com/spring-framework/spring-mvc/spring-hateoas-rest-api-jquery-ajax-example-spring-boot

Spring HATEOAS Rest API + JQuery Ajax POST/GET example | Spring Boot

In this tutorial, JavaSampleApproach shows you a Spring Boot example that uses Spring HATEOAS Rest API with JQuery Ajax.

Related Posts:

I. Overview

1. Goal

We'll build a Spring Boot Application in that:

  • HATEOAS REST Service provides interface for interacting with Customer Database.
  • Client calls API by using JQuery Ajax POST/GET:
  • POST: submit new Order for specific Customer by CustomerId (assume that we have had Customer Database before: 3 customers, we just add new Order information).
  • GET: retrieve Customer Data (Id, Name, Orders List) by CustomerId

When displaying Customer Data for HTTP GET, our application can also show links to current Customer and its Orders.

2. Technology

  • Java 1.8
  • Maven 3.3.9
  • Spring Tool Suite – Version 3.8.4.RELEASE
  • Spring Boot: 1.5.4.RELEASE

    3. Project Structure

    spring-hateoas-ajax-post-get-structure

  • HATEOAS REST Service:

  • Customer class extends Spring HATEOAS ResourceSupport.

  • CustomerRepository provides repository methods and custom finder methods for CustomerController to interact with Customer, Order database.

  • CustomerController is a REST Controller which has request mapping methods for RESTful requests such as:
    /{id}, /{id}/orders, /postorder , /getcustomer/{id}

  • Request and Response class define data structures for returned data of HTTP POST/GET.

For more details about creating HATEOAS REST Service, please visit: How to start Spring HATEOAS RestAPI with Spring Boot
  • JQuery Ajax POST/GET:
  • home.jsp contains form and elements for submitting POST/GET request.
  • ajax() POST/GET methods in get.js, post.js Javascript file.
  • WebController maps url to home.jsp page.
For more simple example about JQuery Ajax POST/GET, please visit: How to integrate JQuery Ajax POST/GET & Spring MVC | Spring Boot
  • Configuration for JSP page and static resources in application.properties
  • Dependencies for Spring HATEOAS, WEB MVC, Tomcat in pom.xml
To know how to make application work with JSP page and static resources, please visit: How to start with JSP page and static resource in Spring Boot

II. Practice

1. Create Spring Boot project

  • Using Spring Tool Suite/Eclipse to create Project (WAR packaging), ServletInitializer and SpringBootApplication class will be created automatically.
  • Add Dependencies to pom.xml file:

More at:

https://grokonez.com/spring-framework/spring-mvc/spring-hateoas-rest-api-jquery-ajax-example-spring-boot

Spring HATEOAS Rest API + JQuery Ajax POST/GET example | Spring Boot

Bình luận


White
{{ comment.user.name }}
Bỏ hay Hay
{{comment.like_count}}
Male avatar
{{ comment_error }}
Hủy
   

Hiển thị thử

Chỉnh sửa

Male avatar

loveprogramming

448 bài viết.
78 người follow
Kipalog
{{userFollowed ? 'Following' : 'Follow'}}
Cùng một tác giả
Male avatar
1 0
Tutorial Link: (Link) (Ảnh) Django is a Pythonbased free and opensource web framework that follows the modeltemplateview architectural pattern. A...
loveprogramming viết 6 tháng trước
1 0
Male avatar
1 0
https://loizenai.com/angular11nodejspostgresqlcrudexample/ Angular 11 Node.js PostgreSQL Crud Example (Ảnh) Tutorial: “Angular 11 Node.js Postg...
loveprogramming viết 5 tháng trước
1 0
Male avatar
1 0
Angular Spring Boot jwt Authentication Example Github https://loizenai.com/angularspringbootjwt/ (Ảnh) Tutorial: ” Angular Spring Boot jwt Authe...
loveprogramming viết 5 tháng trước
1 0
Bài viết liên quan
Male avatar
0 0
https://grokonez.com/frontend/angular/angular6/kotlinspringbootangular6crudhttpclientmysqlexamplespringdatajparestapisexample Kotlin Spring Boot +...
loveprogramming viết 1 tháng trước
0 0
White
9 0
Có bao giờ bạn thắc mắc, chuyện gì thực sự diễn ra khi chúng ta gõ một địa chỉ trang web (ví dụ: (Link)) lên trình duyệt và nhấn Enter? Đầu tiên, t...
Lam Pham viết hơn 3 năm trước
9 0
{{like_count}}

kipalog

{{ comment_count }}

bình luận

{{liked ? "Đã kipalog" : "Kipalog"}}


Male avatar
{{userFollowed ? 'Following' : 'Follow'}}
448 bài viết.
78 người follow

 Đầu mục bài viết

Vẫn còn nữa! x

Kipalog vẫn còn rất nhiều bài viết hay và chủ đề thú vị chờ bạn khám phá!