Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Basic project demonstrating using an Angular front end to communicate with a Spring back end REST API

Notifications You must be signed in to change notification settings

KBeltz/spring-angular

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Angular Demo Application

Prep work: How to use this application

  • Fork this repository
  • Open spring-backend in IntelliJ or your java IDE of choice, and run it
  • In Terminal or Git Bash, navigate to the angular-frontend directory
  • Run npm install
  • Run ng serve --proxy-config proxy.conf.json
  • Open your browser, and navigate to http://localhost:4200

** Note: not all features are fully built out for this demo application. Try to add one of your own!

Step 1: Create your project

  • Create a new project in IntelliJ using Spring Initializr, or via https://start.spring.io
  • Project options:
    • Project SDK: openjdk-15 or whatever the default is
    • Starter service URL: Default https://start.spring.io
    • Group: com.example
    • Artifact: task_manager
    • Type: Gradle
    • Language: Java
    • Packaging: Jar
    • Java version: 11
    • Version/Name/Description/Package: leave as default
  • Dependencies:
    • Web: Spring Web, to get the REST controllers, request mappings
    • SQL: Spring Data JPA, to make it easier to access/save data in the database; you may see it referred to as an ORM, or Object Relational Mapper
    • SQL: H2 Database, lightweight in-memory database with minimal configuration
  • That's it! Click Next > Finish or Generate, depending on whether you're in Intellij or https://start.spring.io
  • Also, feel free to bookmark or fork this repository to refer to later

Concepts: MVC vs API

MVC: Model, View, Controller

  • A software design pattern that separates an application into three main logical components
    • Model: describes the data and its related logic
    • View: presentation of the data
    • Controller: controls user interaction
  • Examples

API: Application Programming Interface

Step 2: Create your Model

  • What data types and annotations do we need to use here?
  • Generate constructor(s)
  • Generate getters/setters

Step 3: Create your Repository

Step 4: Create your Controller

Communicating with the front end application

  • Now look at how we have added the @CrossOrigin annotation in TaskController.java - this will allow us to make requests locally from a separate front end application
  • Try running angular-frontend at the same time as your java project, and go to localhost:4200/ in your browser

About

Basic project demonstrating using an Angular front end to communicate with a Spring back end REST API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •