Start LIne
GET
, POST
, PUT
, DELETE
, OPTIONS
등등이 있다.GET
과 POST
가 쓰인다./login
GET /search HTTP/1.1
Headers
:
이 사용됨)key:value
HOST: [google.com](http://google.com)
⇒ Key = HOST
, Value = google.com
general headers
, request headers
, entity headers
)application/json
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" }
Status Line
200
HTTP/1.1 404 Not Found
Headers
User-Agent
대신 Server
헤더가 사용된다.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>
/update
url에서 어떤 메소드를 요청 가능한지 알고 싶으면 먼저 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)
POST
와 비슷하다. 데이터를 생성 할 때 사용되는 MethodPOST
와 겹치기 때문에 PUT
을 사용하는 곳도 있고 POST
로 통일해서 사용하는 곳도 있는데, 최근 몇년 사이에 **POST
에 밀려서 잘 사용 안되는 추세.**HTTP/1.1 301 Moved Permanently Location: http://www.example.org/index.asp
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
/login
, /news
https://finance.naver.com/marketindex/
POST
, GET
웹상에서 사용되는 여러 리소스를 HTTP URI로 표현하고 그 리소스에 대한 행위를 HTTP Method로 정의하는 방식.
GET
과 POST
만 사용한다.PUT
과 DELETE
등도 사용하는 곳도 있지만, 그냥 GET
과 POST
만 사용하는 것이 단순하기 때문에 GET
과 POST
만 사용하는 추세.예를 들어, 삼성전자 주식 정보를 받기 위한 HTTP 요청:
HTTP GET [https://api.trueshort.com/stock/005930](https://api.trueshort.com/stock/005930)
유저의 보유 주식 종목들을 DB에 저장하는 HTTP 요청:
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/stock/005930)
요청의 경우, 문서나 주석이 없이도 "https://api.trueshort.com 라는 API에서 삼성전자 주식에 관한 정보를 HTTP 요청을 통해 받아오는 구나" 라는 해석이 쉽게 가능하다./
(슬래시)는 계층 관계를 나타낼때 사용된다.https://api.trueshort.com/stock/005930
이라는 구조라면, KOSPI에 속해있는 주식(Stock)중 삼성전자(005930)dmf skxksosms rjtdlek.https://api.shopping.com/books/novel/stephenking
이라는 구조 이라면, 책들 중 소설 그리고 소설 중 Stephen King의 소설을 나타내는 구조이다._
(Underscore)는 주로 포함하지 않고 또한 영어 대문자보다 소문자를 쓴다. 그리고 너무 긴 단어는 잘 사용하지 않는다. 이 모든건 가독성을 높이기 위해서다./books/novel/stephenking
이라고 하지 /books/novel/get-stephenking
이라고 잘 하지 않는다.GET
, POST
같은 HTTP Method를 통해 표현하기 때문이다.