HTTP 메서드
HTTP 프로토콜을 사용하여 웹서버에 있는 자원을 액세스 할수 있는 대표적인 메서드(Method)를 아래 간단하게 정리한다.
Method | 동작 내용 |
GET(Read) | 서버의 자료(Header+Body)를 클라이언트로 보내 줄 것을 요청 |
POST(Create) | 데이터/파일을 Body에 넣어 서버로 전달 → 서버에 새로운 리소스 생성 |
PUT(Update) | 데이터/파일을 Body에 넣어 서버로 전달 → 서버에 있는 리소스 갱신 |
DELETE | 서버에 있는 자료(리소스)를 삭제 |
HEAD | 서버의 자료중 Header 부분만 클라이언트로 보내 줄 것을 요청 |
HTTP 메서드 사용의 예
참조링크 → https://blog.4psa.com/rest-best-practices-choosing-http-methods/
GET
# Request to fetch your favorite photo
GET /rest/photos/1234 HTTP 1.1
Host: www.rest.example.com
# Response contains some properties of the photo resource
HTTP/1.1 200 OK
Content-Type: application/json
{"id":"1234","name":"My favorite photo","link":"http://photo.com/photo/location"}
POST
# Request to save your favorite photo
POST /rest/photos HTTP 1.1
Host: www.rest.example.com
{“name”:”My favorite photo”,”link”:”http://photo.com/photo/location”}
# Response contains the representation of the photo resource
HTTP/1.1 201 Created
Content-Type: application/json
{"id":"1234","name":"My favorite photo","link":"http://photo.com/photo/location"}
PUT
# Request to update your favorite photo
PUT /rest/photos/1234 HTTP 1.1
Host: www.rest.example.com
{“id”:”1234″,”name”:”My awesome photo”}
# Response does not contain any body
HTTP/1.1 204 No Content
Content-Type: application/json
DELETE
# Request to delete your ugly photo
DELETE /rest/photos/1234 HTTP 1.1
Host: www.rest.example.com
# Response
HTTP/1.1 204 No Content
HEAD
# Request to query about the photo service
HEAD /rest/photos/1234 HTTP 1.1
Host: www.rest.example.com
# Response contains the same as GET
HTTP/1.1 200 OK
Content-Type: application/json