Monday, April 20, 2020

MicroService With Spring Boot Project Live Demo full project

Microsercices and Restful APIs with Spring Boot Project with code and Brief step:


Monolithic Architecture - Challenges

  • Large and Complex Application
  • Slow Development
  • Blocks Continuous Development
  • Unscalable
  • Unreliable
  • Inflexible
  • Separate business logic functions
  • Instead of one big program, several small applications
  • Communicates via well defined APIs usually HTTP
  • In demand

Microservices Advantages

  • Language independent
  • First iteration
  • Fault Isolation
  • Pair well with containers
  • Scalable

Microservices - Disadvantages

  • Complex networking
  • Overhead
[]Database
[]Servers

Monolithic Architecture:

Monolithic Architecture is like a big container wherein all the software components of an application are assembled together and tightly.

Actuator: It is a feature that will help to monitor and manage our application

Pattern: make microservices work well together

Technologies: Libraries and frameworks to solve common problems


  • Restful Web Services with Spring Boot
  • Microservices with spring cloud

WEB SERVICE

Software system designed to support interoperable machine to machine interaction over a network

3 KEYS

  1. Designed for machine to machine (application to application) interaction
  2. Should be interoperable - Not platform dependent
  3. Should allow communication over a network

Service Definition:

  • Request/Response Format
  • Request Structure
  • Response Structure
  • Endpoint
Section 1: Introduction
1. Microservices and RESTful APIs with Spring Boot
3. Introduction to the Course & Course Guide
Section 2: Introduction To Web Services
4. What is a Web Service?
5. Important How Questions related to Web sercice
6. Web Services - Key Terminology
7. Introduction to SOAP Web Services
8. Introduction to RESTful Web Services
9. SOAP vs RESTful Web Services
Section 3: Restful Web Services with
Spring Boot
10. Section Introduction - RESTful Web Services
with Spring Boot
11. Step 01 - Initializing a RESTful Services
Project with Spring Boot
12. Fastest Approach to Solve All Your
Exceptions
13. Step 02 - Understanding the RESTful Services
Step 03 - Creating a Hello World Service
15. Step 04 - Enhancing the Hello World Service
to return a Bean
16. Step 05 - Quick Review of Spring Boot Auto
Configuration and Dispatcher Servlet
17. Step 06 - Enhancing the Hello World Service
with a Path Variable
18. Step 07 - Creating User Bean and User
Service
19. Step 08 - Implementing GET Methods for
User Resource
20. Step 09 - Implementing POST Method to
create User Resource
21. Step 10 - Enhancing POST Method to return
correct HTTP Status Code and Location
22. Step 11 - Implementing Exception Handling
- 404 Resource Not Found
23. Step 12 - Implementing Generic Exception
Handling for all Resources
24. Step 13 - Exercise : User Post Resource and
Exception Handling
25. Step 14 - Implementing DELETE Method to
delete a User Resource
26. Recommended Spring Boot Version -
2.1.3.RELEASE
27. Step 15 - Implementing Validations for
RESTful Services
28. Quick Tip : HATEOAS Recent Changes
29. Step 16 - Implementing HATEOAS for
RESTful Services
30. Step 17 - Overview of Advanced RESTful
Service Features
31. Step 18 - Internationalization for RESTful
Services
32. Step 18 Part 2 - Internationalization for
RESTful Services
33. Step 19 - Content Negotiation -
Implementing Support for XML
34. Step 20 - Configuring Auto Generation of
Swagger Documentation
35. Step 21 - Introduction to Swagger
Documentation Format
36. Course Update : Incompatibility in recent
versions of Swagger and Hateoas
37. Step 22 - Enhancing Swagger
Documentation with Custom Annotations
38. Step 23 - Monitoring APIs with Spring Boot
Actuator
39. Step 24 - Implementing Static Filtering for
RESTful Service
40. Step 25 - Implementing Dynamic Filtering
for RESTful Service
41. Step 26 - Versioning RESTful Services - Basic
Approach with URIs
42. Step 27 - Versioning RESTful Services -
Header and Content Negotiation Approach
43. Step 28 - Implementing Basic Authentication
with Spring Security
44. Step 29 - Overview of Connecting RESTful
Service to JPA
45. COURSE UPDATE : H2 Database URL
46. Step 30 - Creating User Entity and some test
data
47. Step 31 - Updating GET methods on User
Resource to use JPA
48. Step 32 - Updating POST and DELETE
methods on User Resource to use JPA
49. Step 33 - Creating Post Entity and Many to
One Relationship with User Entity
50. Step 34 - Implementing a GET service to
retrieve all Posts of a User
51. Step 35 - Implementing a POST service to
create a Post for a User
52. Step 36 - Richardson Maturity Model
53. Step 37 - RESTful Web Services - Best



28 Minutes:

Alt Ctrl Insert ==> new class,package and ohters
Alt Insert ==> insert constructor,getter setter and ohters
Alt Enter ==> insert import
*******************************************************************************************************************************
                                                                                 1st class: 04/12/2020


Web services: service delivered to web. machine to machine interaction, should be interoperable( not platform dependent) ,  communication over a network.
application have web --> business --> data
application --request> web services
application <--response-- web services
response and request format: XML and JSON
Service definition: ---> request response format, request structure, response structure, end point
mvn clean -- mvn clean install
to find port -- netstat -nao
to kill pid -- taskkill /F /PID number of pid of port
Add dependency: Spring web, devtools, JPA , H2 datbase





package com.udemy.rest.webservices.restwebservices;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class RestWebServicesApplication {

public static void main(String[] args) {
SpringApplication.run(RestWebServicesApplication.class, args);
}

}


package com.udemy.rest.webservices.restwebservices;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

// controller
@RestController
public class HelloWorldController {
//GET
//URI - /hello-world
//method - "hello world"
@RequestMapping(method = RequestMethod.GET, path = "/hello-world")
public String helloWorld(){
return "Hello World";
}
}
// go to browser: http://localhost:8080/hello-world and Output: Hello World

POM
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.13.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.udemy.rest.webservices</groupId>
<artifactId>rest-web-services</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>rest-web-services</name>
<description>Demo project for Spring Boot</description>

<properties>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>

*******************************************************************************************************************************
                                                                                 2nd class: 04/13/2020


package com.udemy.rest.webservices.restwebservices;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
// controller
@RestController
public class HelloWorldController {
//GET
//URI - /hello-world
//method - "hello world"
// @RequestMapping(method = RequestMethod.GET, path = "/hello-world")
@GetMapping(path = "/hello-world")
public String helloWorld(){
return "Hello World";
}
@GetMapping(path = "/hello-world-bean")
public HelloWorldBean helloWorldBean(){
return new HelloWorldBean("Hello World");
}
}

package com.udemy.rest.webservices.restwebservices;

public class HelloWorldBean {
private final String message;

//constructor
public HelloWorldBean(String message) {
this.message = message;
}
//getter setter
public String getMessage() {
return message;
}
//to string
@Override
public String toString() {
return "HelloWorldBean{" +
"message='" + message + '\'' +
'}';
}
}


*******************************************************************************************************************************

Only adding path variable:
package com.udemy.rest.webservices.restwebservices;

import org.springframework.web.bind.annotation.*;

// controller
@RestController
public class HelloWorldController {
//GET
//URI - /hello-world
//method - "hello world"
// @RequestMapping(method = RequestMethod.GET, path = "/hello-world")
@GetMapping(path = "/hello-world")
public String helloWorld(){
return "Hello World";
}
//passing message
@GetMapping(path = "/hello-world-bean")
public HelloWorldBean helloWorldBean(){
return new HelloWorldBean("Hello World");
}
//hello-world/path-variable/in28minutes
@GetMapping(path = "/hello-world/path-variable/{name}")
public HelloWorldBean helloWorldPathVariable(@PathVariable String name){
return new HelloWorldBean(String.format("Hello World %s", name));
}
}



POST - resource created HTTP response 201


exception handling customized.
*******************************************************************************************************************************
                                                                                 3rd class: 04/13/2020




// HATEOAS - retrive data for that user and also tells how to retrive others

this makes xml format response
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-xml -->
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.10.2</version>
</dependency>
*******************************************************************************************************************************
                                                                                 4th class: 04/14/2020
Swagger- documentation our services by using swagger
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.4.0</version>
</dependency>

3 http://localhost:8080/actuator helps to see service in browser, monitoring

*******************************************************************************************************************************
                                                                                 5th class: 04/15/2020
*******************************************************************************************************************************




*******************************************************************
References:
  1. Repo: https://github.com/in28minutes/spring-microservices
  2. Spring project: https://start.spring.io/

No comments:

Post a Comment