Angular 4 + Spring Boot + Cassandra CRUD example

In this tutorial, JavaSampleApproach shows you Angular 4 Http Client & Spring Boot Server example that uses Spring Data to interact with Cassandra and Angular 4 as a front-end technology to make request and receive response.

Related Posts:
How to use Angular Http Client to fetch Data from SpringBoot RestAPI – Angular 4
How to use Angular HttpClient to POST, PUT, DELETE data on SpringBoot Rest APIs – Angular 4
How to start Spring Data Cassandra with SpringBoot

I. Technologies

– Java 1.8
– Maven 3.3.9
– Spring Tool Suite 3.9.0.RELEASE
– Spring Boot 1.5.9.RELEASE
– Angular 4
– Cassandra 3.9.0

II. Overview

angular-http-service-architecture

1. Spring Boot Server

angular-4-spring-data-cassandra-server-overview

A Spring Boot Cassandra – example:
How to start Spring Data Cassandra with SpringBoot

2. Angular 4 Client

angular4-springdata-cassandra-httpclient-overview
For more details:
– About Angular 4 Routing:
How to work with Angular Routing – Spring Boot + Angular 4
– About Angular Http Client to GET/POST/DELETE:
+ How to use Angular Http Client to fetch Data from SpringBoot RestAPI – Angular 4
+ How to use Angular HttpClient to POST, PUT, DELETE data on SpringBoot Rest APIs – Angular 4

III. Practice

1. Project Structure

1.1 Spring Boot Server

angular-4-spring-data-cassandra-server-structure

– Class Customer corresponds to customer table.
CustomerRepository is an interface extends Spring Data CassandraRepository, will be autowired in CustomerController for implementing repository methods and finder methods.
CustomerController is a REST Controller which has request mapping methods for RESTful requests such as: getAll, create, update, delete Customers.
– Configuration for Spring Data Cassandra properties in application.properties
– Dependencies for Spring Boot and Spring Data Cassandra in pom.xml

1.2 Angular 4 Client

angular4-springdata-cassandra-client-structure

In this example, we have:
– 3 components: customers-list, customer-details, create-customer.
– 3 modules: FormsModule, HttpClientModule, AppRoutingModule.
customer.ts: class Customer (id, name, age, active).
customer.service.ts: Service for HttpClient methods.

2. How to do

2.0 Set up Cassandra

Open Cassandra CQL Shell:

– Create Cassandra keyspace with name javasampleapproach:

– Create customer table for javasampleapproach keyspace:

2.1 Spring Boot Server
2.1.1 Dependency

2.1.2 Customer – Data Model

2.1.3 Repository

2.1.4 REST Controller

2.1.5 Configuration for Spring Data Cassandra

2.2 Angular 4 Client
2.2.1 AppModule

2.2.2 Model

2.2.3 DataService

2.2.4 Components

– CustomerDetailsComponent:

– CustomersListComponent:

– CreateCustomerComponent:

2.2.5 AppRoutingModule

2.2.6 App Component

3. Run & Check Result

Build and Run Spring Boot project with commandlines: mvn clean install and mvn spring-boot:run.
– Run the Angular App with command: npm start.

– Open browser for url http://localhost:4200/:
Add Customer(Jack,27):
angular4-springdata-cassandra-httpclient-result-add-customer

Add more customers, check Cassandra table:
angular4-springdata-cassandra-httpclient-result-add-customers-shell

Choose tab Customers:
angular4-springdata-cassandra-httpclient-result-show-customers

Update active status by click on Active label:
angular4-springdata-cassandra-httpclient-result-update-customer

Delete a customer (Jack):
angular4-springdata-cassandra-httpclient-result-delete-customer

Check Cassandra table again, Katherin‘s active status has changed, and Jack data has been deleted:
angular4-springdata-cassandra-httpclient-result-update-customers-shell

Click Delete All button:
angular4-springdata-cassandra-httpclient-result-delete-all-customers

IV. Source Code

SpringBootAngular4Cassandra
Angular4HttpClient-CassandraCRUD

By JavaSampleApproach | November 29, 2017.


Related Posts


Got Something To Say:

Your email address will not be published. Required fields are marked *

*