Move articles from spring-core-6 module to other spring-boot modules (#13722)
* Move articles from spring-core-6 module to other spring-boot modules * JAVA-19559 Move articles from spring-core-6 module to other spring-boot-3 modules * JAVA-19559 Minor spacing change * JAVA-19559 Revert Minor spacing change
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
package com.baeldung.httpinterface;
|
||||
|
||||
public record Book(long id, String title, String author, int year) {}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.httpinterface;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import org.springframework.web.reactive.function.client.support.WebClientAdapter;
|
||||
import org.springframework.web.service.invoker.HttpServiceProxyFactory;
|
||||
|
||||
@Component
|
||||
public class BooksClient {
|
||||
|
||||
private final BooksService booksService;
|
||||
|
||||
public BooksClient(WebClient webClient) {
|
||||
HttpServiceProxyFactory httpServiceProxyFactory =
|
||||
HttpServiceProxyFactory.builder(WebClientAdapter.forClient(webClient))
|
||||
.build();
|
||||
booksService = httpServiceProxyFactory.createClient(BooksService.class);
|
||||
}
|
||||
|
||||
public BooksService getBooksService() {
|
||||
return booksService;
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.baeldung.httpinterface;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.service.annotation.DeleteExchange;
|
||||
import org.springframework.web.service.annotation.GetExchange;
|
||||
import org.springframework.web.service.annotation.PostExchange;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
interface BooksService {
|
||||
|
||||
@GetExchange("/books")
|
||||
List<Book> getBooks();
|
||||
|
||||
@GetExchange("/books/{id}")
|
||||
Book getBook(@PathVariable("id") long id);
|
||||
|
||||
@PostExchange("/books")
|
||||
Book saveBook(@RequestBody Book book);
|
||||
|
||||
@DeleteExchange("/books/{id}")
|
||||
ResponseEntity<Void> deleteBook(@PathVariable("id") long id);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user