Skip to content

Library6: ThymeLeaf Web Project RestTemplate (data from API Rest)

Albert edited this page Jun 17, 2022 · 11 revisions

Welcome to the cifojava2022-5 wiki!

ThymeLeaf Web Project RestTemplate (data from API Rest)

Base project

  • Base project:

    • @Entity book from Library1 and JPA-H2: library6server
    • POJO book from Library5 and TH: library6client
    • POM
    • ThymeLeaf dependency
    • DataBase H2: Library6server
    • Application.properties
    • @Service, @CrudRepository JPA 2.0
    • @Test JUnit Jupiter
  • To work from base-project

    • Architectrure Server (Spring Boot) <API REST> Client (Spring Boot)
    • RestTemplate class :** Synchronous client to perform HTTP requests**, exposing a simple, template method API over underlying HTTP client libraries such as:
      • the JDK HttpURLConnection,
      • Apache HttpComponents,
      • ReponseEntity,
      • HttpEntity
      • and others.
    • WebClient to replace RestTemplate : on-blocking, reactive client to perform HTTP requests, exposing a fluent, reactive API over underlying HTTP client libraries such as Reactor Netty.

New tools

  • Architectrure : both Spring Boot projects, different ports: 8080/8086

    Spring Boot Server-Client

  • RestTemplate :

        public Iterable<Book> getAllBooks() {
    
            ResponseEntity<List<Book>> response = restTemplate.exchange(
               "http://localhost:8080/api/books", HttpMethod.GET,
               null,
               new ParameterizedTypeReference<List<Book>>() {
                });
    
            List<Book> books = response.getBody();
         return books;
         }
    

Versions