Skip to content

Feign client 이용하여 tour API 호출 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

pingu9
Copy link
Contributor

@pingu9 pingu9 commented Oct 9, 2023

미완성입니다만(호출 자체는 잘 되지만 요청 변수 등이 하드코딩 되어있습니다) feign client 이용하여 호출하는 방식이 어떤지 의견을 묻고싶어 우선 PR을 올립니다.

Copy link
Contributor

@cheolwon1994 cheolwon1994 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feign Client 이용한 API 호출이 좋아보이는데 한가지 궁금한점이 있습니다. 찾아보니 구현체를 자동으로 구현해준다고 되어있는데, 저희가 원하는 대로 커스텀 할 수 있는건가요? 조회 후 저희에게 맞게 변환하고 DB에 저장하는 작업까지도요!

@cheolwon1994
Copy link
Contributor

cheolwon1994 commented Oct 10, 2023

FeignClient를 사용한다면 다음과 같은 configuration도 있으면 좋을것 같습니다!
참고 URL: https://forkyy.tistory.com/10

public class FeignClientHeaderConfiguration {

    public static final String APPLICATION_FORM_URLENCODED_UTF8_VALUE =
        MediaType.APPLICATION_FORM_URLENCODED_VALUE + ";charset=utf-8";

    @Bean
    public RequestInterceptor requestInterceptor() {
        return requestTemplate -> requestTemplate.header(HttpHeaders.CONTENT_TYPE, APPLICATION_FORM_URLENCODED_UTF8_VALUE);
    }

}

@dev-khg
Copy link
Contributor

dev-khg commented Oct 10, 2023

Feign client 적용하여 호출하면 부가 코드를 줄일 수 있어 좋을 것 같습니다!

@pingu9
Copy link
Contributor Author

pingu9 commented Oct 10, 2023

FeignClient를 사용한다면 다음과 같은 configuration도 있으면 좋을것 같습니다! 참고 URL: https://forkyy.tistory.com/10

public class FeignClientHeaderConfiguration {

    public static final String APPLICATION_FORM_URLENCODED_UTF8_VALUE =
        MediaType.APPLICATION_FORM_URLENCODED_VALUE + ";charset=utf-8";

    @Bean
    public RequestInterceptor requestInterceptor() {
        return requestTemplate -> requestTemplate.header(HttpHeaders.CONTENT_TYPE, APPLICATION_FORM_URLENCODED_UTF8_VALUE);
    }

}

좋네요~ 에러 응답일 경우 공통 파싱 처리 등도 Configuration 통해 지정할 수 있을 것으로 보입니다

@pingu9
Copy link
Contributor Author

pingu9 commented Oct 10, 2023

Feign Client 이용한 API 호출이 좋아보이는데 한가지 궁금한점이 있습니다. 찾아보니 구현체를 자동으로 구현해준다고 되어있는데, 저희가 원하는 대로 커스텀 할 수 있는건가요? 조회 후 저희에게 맞게 변환하고 DB에 저장하는 작업까지도요!

음.. 커스텀하고 싶은 쪽이 어떤 쪽이신걸까요? 기본으로 제공하는 구현체는 Spring의 RestController와 거의 유사한 방식으로 사용할 수 있도록 구현되어있습니다.
보통의 경우에는 이 PR에 나온것처럼 우선 형식을 맞춰 Response Body를 받은 후에 저희가 원하는 형태로 dto 매핑을 하는 방식으로 사용할 것 같네요!

@cheolwon1994
Copy link
Contributor

잘못눌러서 PR 닫았다가 다시 열었습니다

@inyoung0215
Copy link
Member

오 feign client는 처음 접해보네요! 👍 역시 세상은 넓군요..

}

@Bean
public ResponseInterceptor responseInterceptor(CatcherConverter catcherConverter) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

홍근님께서 올려주신 PR 참고하여 response converter를 적용해보았습니다

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feign Inteceptor를 통한 공통처리 좋네요!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants