Query Parameter

이지은·2021년 2월 26일
1

Query Parameter

user을 위해 page를 만들면 그 page를 식별하기 위한 path 가 필요하다.
You have to control user list when creating some social service. You nedd to path identified parameter to that page. You can achieve that by using this kind of get parameter.

users?id=234 # Fetch a user who has id of 234

그리고 backend에서 id variable을 가져올 수 있다.
이게 바로 Query string!

Path Variable

/users/234 # Fetch a user who has id 234

그럼 어떤 경우에 Path variable을 쓰고 어떤 경우에 Query Parameter을 쓰는걸까..?

: resource를 식별할 때 Path Variable을 사용하고 sort/filter items 일때 query parameter을 써야 한다.

/users # Fetch a list of users
/users? job= developer # Fetch a list of developer user
/users/234 # Fetch a user who has id 234

근데 side effect가 있을 수가 있다. basic CRUD functinos에서 url과 다른 query parameter을 정의할 필요가 없다. 뭘 하고 싶은지에 따라 HTTP method을 바꾸면 된다.

/users [GET]    # Fetch a list of users
/users [POST]    #Create new user
/users/234 [PUT]  # Update user
/users/234 [DELETE]  # remove user

CRUD process를 extra endpoint/Query Parameter 없이 진행 할 수 있다. Simple!

개발의 효율성을 높이기 위해 이런 기준을 따르는게 필요하다!

RESTFUL API!!

profile
Front-end 🐕🦶

0개의 댓글