File tree 5 files changed +54
-0
lines changed
api-server/src/main/kotlin/com/kshired/boilerplate/apiserver/controller/example
clients/client-example/src/main/kotlin/com/kshired/boilerplate/clients/client/example
5 files changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com.kshired.boilerplate.apiserver.controller.example
2
+
3
+ import com.kshired.boilerplate.apiserver.controller.example.response.CatFactResponse
4
+ import com.kshired.boilerplate.clients.client.example.ExampleClient
5
+ import com.kshired.boilerplate.common.util.response.ApiResponse
6
+ import org.springframework.web.bind.annotation.GetMapping
7
+ import org.springframework.web.bind.annotation.RequestMapping
8
+ import org.springframework.web.bind.annotation.RestController
9
+
10
+ @RestController
11
+ @RequestMapping(" /api/v1/example" )
12
+ class ExampleController (
13
+ // (예시용) 보통 client를 controller에서 직접 사용하지는 않습니다. service 혹은 구현 계층에서 사용하는게 일반적입니다.
14
+ private val exampleClient : ExampleClient
15
+ ) {
16
+ @GetMapping(" /cat/fact" )
17
+ fun getCatFact (): ApiResponse <CatFactResponse > {
18
+ return ApiResponse .success(CatFactResponse (exampleClient.getCatFacts()))
19
+ }
20
+ }
Original file line number Diff line number Diff line change
1
+ package com.kshired.boilerplate.apiserver.controller.example.response
2
+
3
+ data class CatFactResponse (
4
+ val fact : String
5
+ )
Original file line number Diff line number Diff line change
1
+ package com.kshired.boilerplate.clients.client.example
2
+
3
+ import com.kshired.boilerplate.clients.client.example.response.ExampleResponse
4
+ import org.springframework.cloud.openfeign.FeignClient
5
+ import org.springframework.web.bind.annotation.GetMapping
6
+
7
+ @FeignClient(name = " example" , url = " https://catfact.ninja" )
8
+ interface ExampleApi {
9
+ @GetMapping(" /fact" )
10
+ fun getFact (): ExampleResponse
11
+ }
Original file line number Diff line number Diff line change
1
+ package com.kshired.boilerplate.clients.client.example
2
+
3
+ import org.springframework.stereotype.Component
4
+
5
+ @Component
6
+ class ExampleClient (
7
+ private val exampleApi : ExampleApi
8
+ ) {
9
+ fun getCatFacts (): String {
10
+ return exampleApi.getFact().fact
11
+ }
12
+ }
Original file line number Diff line number Diff line change
1
+ package com.kshired.boilerplate.clients.client.example.response
2
+
3
+ data class ExampleResponse (
4
+ val fact : String ,
5
+ val length : Int
6
+ )
You can’t perform that action at this time.
0 commit comments