HTTP 통신 방식
HTTP Request 구조
status line
/ headers
/ body
)Start Line
GET /search HTTP/1.1
GET
과 POST
를 사용한다./login
Headers
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Type: application/json
Content-Length: 257
Host: google.com
User-Agent: HTTPie/0.9.3
Body
POST /payment-sync HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 83
Content-Type: application/json
Host: intropython.com
User-Agent: HTTPie/0.9.3
{
"imp_uid": "imp_1234567890",
"merchant_uid": "order_id_8237352",
"status": "paid"
}
HTTP Response 구조
Status line
, Headers
, Body
)Status Line
HTTP/1.1 404 Not Found
Headers
Body
HTTP/1.1 404 Not Found
Connection: close
Content-Length: 1573
Content-Type: text/html; charset=UTF-8
Date: Mon, 20 Aug 2018 07:59:05 GMT
<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 404 (Not Found)!!1</title>
<style>
*{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
</style>
<a href=//www.google.com/><span id=logo aria-label=Google></span></a>
<p><b>404.</b> <ins>That’s an error.</ins>
<p>The requested URL <code>/payment-sync</code> was not found on this server. <ins>That’s all we know.</ins>
GET
POST
OPTIONS
/update
uri에서 어떤 method를 요청 가능한지 알고 싶으면, 먼저 OPTIONS를 통해 확인한다.http -v OPTIONS http://example.org
OPTIONS / HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 0
Host: example.org
User-Agent: HTTPie/0.9.3
HTTP/1.1 200 OK
Allow: OPTIONS, GET, HEAD, POST
Cache-Control: max-age=604800
Content-Length: 0
Date: Mon, 20 Aug 2018 08:37:45 GMT
Expires: Mon, 27 Aug 2018 08:37:45 GMT
Server: EOS (vny006/0450)
PUT
POST
와 겹치기 때문에 PUT
을 사용하는 곳도 있고, POST
만 사용하는 곳도 있는데, 최근에는 POST
에 밀려서 잘 사용하지 않는 추세다.DELETE
PUT
과 마찬가지로 POST
에 밀려서 잘 사용하지 않는 추세다.200 OK
301 Moved Permanently
400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found
요청된 uri가 존재 하지 않는다는 뜻
http -v google.com/no-such-uri
GET /no-such-uri HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: google.com
User-Agent: HTTPie/0.9.3
HTTP/1.1 404 Not Found
Content-Length: 1572
Content-Type: text/html; charset=UTF-8
Date: Mon, 20 Aug 2018 08:46:48 GMT
Referrer-Policy: no-referrer
500 Internal Server Error
/login
, /news
https://finance.naver.com/marketindex/
HTTP GET https://api.trueshort.com/stock/005930
HTTP POST https://api.trueshort.com/user/portfolio
{
"user_id" : 1,
"stocks": [
"005930",
"298730",
"378900"
]
}
self-descriptiveness
이다.HTTP GET https://api.trueshort.com/stock/005930
요청의 경우, 문서나 줏거의 없이도 https://api.trueshort.com
라는 API에서 삼성전자 주식에 관한 정보를 HTTP요청을 통해 받아온다는 것을 예상하고, 쉽게 해석이 가능하다./
는 계층 관계를 나타낸다.https://api.trueshort.com/kospi/stock/005930
에서, KOSPI에 속해있는 주식(stock) 중 삼성전자(005930)을 나타내는 구조다.https://api.shopping.com/books/novel/stephenking
에서, 책들중 소설 그리고 소설중 Stephen King의 소설을 나타내는 구조다._
는 주로 포함하지 않고 영어는 대문자보다 소문자를 쓴다.
오타 수정해주세요