Kotlin Spring WebFlux Annotation-Based RestAPIs - with SpringBoot 2
Kotlin
87
Spring WebFlux
1
restapi
48
Male avatar

loveprogramming viết ngày 04/04/2021

https://grokonez.com/spring-framework/spring-boot/kotlin-spring-boot/kotlin-spring-webflux-annotation-based-restapis-springboot-2

Kotlin Spring WebFlux Annotation-Based RestAPIs - with SpringBoot 2

Reactive programming is about non-blocking applications. And Spring Framework 5 includes a new spring-webflux module, supports Reactive Streams for communicating backpressure across async components and libraries. So in the tutorial, JavaSampleApproach will guide you through the steps for creating a Kotlin Spring WebFlux Annotation-Based RestAPIs with SpringBoot 2.

Related posts:

I. Technologies

– Java: 1.8
– Maven: 3.5.2
– Spring Tool Suite: Version 3.9.0.RELEASE
– Spring Boot: 2.0.0.M7

  • Kotlin 1.1.61 – Spring Boot Starter Webflux
  • Postman client

    II. Spring WebFlux

    Spring Framework 5.0 supports WebFlux with fully asynchronous and non-blocking and does NOT require the Servlet API(Unlike Spring MVC).

Spring WebFlux supports 2 distinct programming models:
– Annotation-based with @RestController
– Functional with Java 8 lambda style

In the tutorial, we will introduce WebFlux with Annotation-based and Kotlin language.
For starting with WebFlux, SpringBoot supports a collection dependency: spring-boot-starter-webflux.

Kotlin sample code:


import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping(value="/api/customer")
class RestControllerAPIs {

    @GetMapping
    fun getAll(): Flux {
        return Flux.fromIterable(ArrayList(custStores.values));
    }
    
    @GetMapping("/{id}")
    fun getCustomer(@PathVariable id: Long): Mono {
        return Mono.justOrEmpty(custStores.get(id))
    }
    
    ...
}

reactor.core.publisher.Flux: is a standard Publisher representing a reactive sequence of 0..N items, optionally terminated by either a success signal or an error.
reactor.core.publisher.Mono: Mono is a specialized Publisher that emits at most single-valued-or-empty result.

https://grokonez.com/spring-framework/spring-boot/kotlin-spring-boot/kotlin-spring-webflux-annotation-based-restapis-springboot-2

Bình luận


White
{{ comment.user.name }}
Bỏ hay Hay
{{comment.like_count}}
Male avatar
{{ comment_error }}
Hủy
   

Hiển thị thử

Chỉnh sửa

Male avatar

loveprogramming

447 bài viết.
78 người follow
Kipalog
{{userFollowed ? 'Following' : 'Follow'}}
Cùng một tác giả
Male avatar
1 0
Tutorial Link: (Link) (Ảnh) Django is a Pythonbased free and opensource web framework that follows the modeltemplateview architectural pattern. A...
loveprogramming viết 6 tháng trước
1 0
Male avatar
1 0
https://loizenai.com/angular11nodejspostgresqlcrudexample/ Angular 11 Node.js PostgreSQL Crud Example (Ảnh) Tutorial: “Angular 11 Node.js Postg...
loveprogramming viết 5 tháng trước
1 0
Male avatar
1 0
Angular Spring Boot jwt Authentication Example Github https://loizenai.com/angularspringbootjwt/ (Ảnh) Tutorial: ” Angular Spring Boot jwt Authe...
loveprogramming viết 5 tháng trước
1 0
Bài viết liên quan
Male avatar
0 0
https://grokonez.com/frontend/angular/angular6/kotlinspringbootangular6crudhttpclientmysqlexamplespringdatajparestapisexample Kotlin Spring Boot +...
loveprogramming viết 1 tháng trước
0 0
White
9 0
Có bao giờ bạn thắc mắc, chuyện gì thực sự diễn ra khi chúng ta gõ một địa chỉ trang web (ví dụ: (Link)) lên trình duyệt và nhấn Enter? Đầu tiên, t...
Lam Pham viết hơn 3 năm trước
9 0
{{like_count}}

kipalog

{{ comment_count }}

bình luận

{{liked ? "Đã kipalog" : "Kipalog"}}


Male avatar
{{userFollowed ? 'Following' : 'Follow'}}
447 bài viết.
78 người follow

 Đầu mục bài viết

Vẫn còn nữa! x

Kipalog vẫn còn rất nhiều bài viết hay và chủ đề thú vị chờ bạn khám phá!