4가지 상황을 예로 들어 각 메서드를 활용해보자.
정적 데이터 조회
클라이언트
GET /static/star.jpg HTTP/1.1
Host: location:8080
동적 데이터 조회
클라이언트
GET /search?q=hello&hl=ko HTTP/1.1
Host: www.google.com
HTML Form을 통한 데이터 전송
HTML 파일
<form action="/save" method="post">
<input type="text" name="username"/>
<input type="text" name="age"/>
<button type="submit">전송</button>
</form>
클라이언트
POST /save HTTP/1.1
Host: location:8080
Content-Type: application/x-www-form-urlencoded
**username=kim&age=20**
***** Content-type: application/x-www-form-urlencoded 를 사용하면**
***** Content-type: multipart/form-data 를 사용하면**
⇒ 위와 같이 Content-type을 지정하여 사용 할 수 있다.
HTTP API를 통한 데이터 전송
POST /save HTTP/1.1
Host: location:8080
Content-Type: application/json
{
username:kim
age:20
}
우리가 서비스를 만들어야된다고 가정하고 HTTP API를 어떻게 설계할 지 예시를 들어보자.