Web개발/MSA
Restful API 제작시 HiddenHttpMethodFilterConfiguration
테니스치는개발자
2020. 3. 2. 11:10
PUT, DELETE 메소드로는 Web 서비스와 함께 원격지 웹 서버에 파일을 생성하거나 삭제하는 FTP와 유사한 기능을 구현할 수 있다.
그러면 get 이랑 post 만 써서 rest api 를 만들어야 되나???
Nope !
Url 파라미터로 _method=PUT , _method=DELETE 를 사용하고
웹서버 Filter 에서 _method 파라미터의 value값을 http method로 변경하는 spring filter 가 "HiddenHttpMethodFilterConfiguration" 이다.
사용은 간단하다. 아래클래스 하나 만들면 끝.
그러면 GET,POST 메소드만 Request 를 받도록 제한을 하려면??????
CorsWebFilter 를 사용하면 된다.
========================================================================
1
2
3
4
5
6
7
8
|
@Configuration
public class HiddenHttpMethodFilterConfiguration {
@Bean
public HiddenHttpMethodFilter hiddenHttpMethodFilter() {
return new HiddenHttpMethodFilter();
}
}
|