반응형



@QueryParam ? @PathParam?

흔히 API설계하실 때 특히 GET 방식의 URI 만드실 때 쿼리 파라미터로 설계할지 패스파라미터로 설계하실지 고민들하실텐데요.


저또한 많이 고민하다가 관련해서 열띤 토론?을 나눈 stackoverflow글이 있어 공유합니다.



---------------------------------------------------------------------------------------------------------------------------------------


This is what I do.

If there is a scenario to retrieve a record based on id, for example you need to get the details of the employee whose id is 15, then you can have resource with @PathParam.

GET /employee/{id}

If there is a scenario where you need to get the details of all employees but only 10 at a time, you may use query param

GET /employee?start=1&size=10

This says that starting employee id 1 get ten records.

To summarize, use @PathParam for retrieval based on id. 

User @QueryParam for filter or if you have any fixed list of options that user can pass.


[ 자세한건 참고 : StackOverflow]

http://stackoverflow.com/questions/11552248/when-to-use-queryparam-vs-pathparam

-------------------------------------------------------------------------------------------

[ 결 론 ]

결국에는 특정 정보를 가지고 올 때는  PATH PARAMETER를 데이터에 특정 조건(필터)를 주거나 SORT를 해서 가지고 오고자 할 경우에는 쿼리파라미터를 사용하면 좀 더 깔끔하게 API 를 설계하실 수 있을 것 같습니다.

감사합니다.

 




반응형

+ Recent posts