HTTP 메서드는 HTTP 요청이 쿼리된 리소스에 서버에 기대하는 작업을 나타낸다. 즉, 클라이언트가 수행하고자 하는 동작을 정의한다. HTTP 메서드의 종류는 총 9가지가 있다. 그중 주로 쓰이는 메서드는 아래의 5가지가 있다.
조회읽거나 검색할 때 사용데이터를 가져올 때만 사용)응답으로 정보를 기대Readquery(쿼리 파라미터, 쿼리 스트링)을 통해 전달GET /members/100 HTTP/1.1
Host: localhost:8080
HTTP/1.1 200 OK
Content-Type: application.json
Content-Length: 34
{
"username": "young",
"age": 20
}
서버로 요청 데이터 전달클라이언트가 웹 서버에 정보를 제출Content-Type 헤더처리Create 생성(등록)POST /members HTTP/1.1
Content-Type: application.json
{
"username": "young",
"age": 20
}
HTTP/1.1 201 Created
Content-Type: application.json
Content-Length: 34
Location: /members/100
{
"username": "young",
"age": 20
}
있으면 대체없으면 생성(덮어버림)Update POST /members/100 HTTP/1.1
Content-Type: application.json
{
"username": "old",
"age": 50
}
POST /members/100 HTTP/1.1
Content-Type: application.json
{
"age": 50
}
UpdatePATCH /members/100 HTTP/1.1
Content-Type: application.json
{
"age": 50
}
DeleteDELETE /members/100 HTTP/1.1
Host: localhost:8080
참고