Angular + Spring JPA + PostgreSQL example | Angular 4 Http Client - Spring Boot RestApi Server

Tags: angular, springjpa, postgres
Published: 2021-03-25 10:51:37

https://grokonez.com/spring-framework/spring-mvc/angular-4-spring-jpa-postgresql-example-angular-4-http-client-spring-boot-restapi-server

Angular + Spring JPA + PostgreSQL example | Angular 4 Http Client - Spring Boot RestApi Server

In this tutorial, <strong>grokonez</strong> shows you Angular 4 Http Client & Spring Boot Server example that uses <strong>Spring JPA</strong> to interact with <strong>PostgreSQL</strong> and <strong>Angular 4</strong> as a front-end technology to make request and receive response.

Related Posts:
- <a href="https://grokonez.com/spring-framework/spring-boot/use-spring-jpa-postgresql-spring-boot">How to use Spring JPA with PostgreSQL | Spring Boot</a>
- <a href="https://grokonez.com/spring-framework/spring-boot/spring-jpa-postgresql-angularjs-example-spring-boot">Spring JPA + PostgreSQL + AngularJS example | Spring Boot</a>
- <a href="https://grokonez.com/spring-framework/spring-boot/use-angular-http-client-fetch-data-springboot-restapi">How to use Angular Http Client to fetch Data from SpringBoot RestAPI – Angular 4</a>
- <a href="https://grokonez.com/spring-framework/spring-boot/use-angular-httpclient-post-put-delete-data-springboot-rest-apis-angular-4">How to use Angular HttpClient to POST, PUT, DELETE data on SpringBoot Rest APIs – Angular 4</a>

Updated:
- <a href="https://grokonez.com/spring-framework/spring-boot/spring-boot-angular-6-example-spring-data-rest-postgresql-example">Spring Boot + Angular 6 example | Spring Data JPA + REST + PostgreSQL CRUD example</a>

<!--more-->
<h2>I. Technologies</h2>
– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.4.RELEASE
– Spring Boot: RELEASE
– Angular 4
<h2>II. Overview</h2>
<img src="https://grokonez.com/wp-content/uploads/2017/05/angular-http-service-architecture-1.png" alt="angular-http-service-architecture" width="570" height="542" class="alignnone size-full wp-image-5475" />
<h3>1. Spring Boot Server</h3>

<img src="https://grokonez.com/wp-content/uploads/2017/08/angular-4-spring-jpa-postgresql-spring-boot-architecture.png" alt="angular-4-spring-jpa-postgresql-spring-boot-architecture" width="700" height="330" class="alignnone size-full wp-image-7626" />

For more details about Spring JPA - PostgreSQL, please visit:
<a href="https://grokonez.com/spring-framework/spring-boot/use-spring-jpa-postgresql-spring-boot">How to use Spring JPA with PostgreSQL | Spring Boot</a>

<h3>2. Angular 4 Client</h3>
<img src="https://grokonez.com/wp-content/uploads/2017/08/angular-4-spring-jpa-postgresql-angular-architecture.png" alt="angular-4-spring-jpa-postgresql-angular-architecture" width="698" height="342" class="alignnone size-full wp-image-7628" />

For more details:
- About Angular 4 Routing:
<a href="https://grokonez.com/spring-framework/spring-boot/work-angular-routing-spring-boot-angular-4">How to work with Angular Routing – Spring Boot + Angular 4</a>
- About Angular Http Client to GET/POST/DELETE:
+ <a href="https://grokonez.com/spring-framework/spring-boot/use-angular-http-client-fetch-data-springboot-restapi">How to use Angular Http Client to fetch Data from SpringBoot RestAPI – Angular 4</a>
+ <a href="https://grokonez.com/spring-framework/spring-boot/use-angular-httpclient-post-put-delete-data-springboot-rest-apis-angular-4">How to use Angular HttpClient to POST, PUT, DELETE data on SpringBoot Rest APIs – Angular 4</a>

<h2>III. Practice</h2>
<h3>1. Project Structure</h3>
<h4>1.1 Spring Boot Server</h4>
<img src="https://grokonez.com/wp-content/uploads/2017/08/angular-4-spring-jpa-postgresql-spring-boot-structure.png" alt="angular-4-spring-jpa-postgresql-spring-boot-structure" width="347" height="362" class="alignnone size-full wp-image-7630" />

- Class <strong>Customer</strong> corresponds to entity and table <strong>customer</strong>, it should be implemented <strong>Serializable</strong>.
- <strong>CustomerRepository</strong> is an interface extends <strong>CrudRepository</strong>, will be autowired in <strong>CustomerController</strong> for implementing repository methods and custom finder methods.
- <strong>CustomerController</strong> is a REST Controller which has request mapping methods for RESTful requests such as: <code>getAll</code>, <code>postCustomer</code>, <code>delete</code>, <code>findByLastName</code>.
- Configuration for Spring Datasource and Spring JPA properties in <strong>application.properties</strong>
- <strong>Dependencies</strong> for <strong>Spring Boot</strong> and <strong>PostgreSQL</strong> in <strong>pom.xml</strong>
<h4>1.2 Angular 4 Client</h4>
<img src="https://grokonez.com/wp-content/uploads/2017/08/angular-4-spring-jpa-postgresql-angular-structure.png" alt="angular-4-spring-jpa-postgresql-angular-structure" width="418" height="372" class="alignnone size-full wp-image-7631" />

In this example, we focus on:
- 4 components: <strong><em>customers</em></strong>, <strong><em>customer-details</em></strong>, <strong><em>create-customer</em></strong>, <strong><em>search-customer</em></strong>.
- 3 modules: <strong><em>FormsModule</em></strong>, <strong><em>HttpModule</em></strong>, <strong><em>AppRoutingModule</em></strong>.
- <strong><em>customer.ts</em></strong>: class Customer (id, firstName, lastName)
- <strong><em>data.service.ts</em></strong>: DataService for Http Client methods
- <strong><em>proxy.conf.json</em></strong> for integrating Angular Client with Spring Boot Server.

https://grokonez.com/spring-framework/spring-mvc/angular-4-spring-jpa-postgresql-example-angular-4-http-client-spring-boot-restapi-server