Android Basics in Kotlin 중 인터넷을 사용하는 부분을 보기 전에, 앞선 영상에서 HTTP와 REST의 기초를 알려주었다. Retrofit을 본격적으로 공부하기 전에, 이 내용을 정리해두려고 한다.
예 : https://google.com/search?q=android
https:// : Scheme://로 끝남.google.com : Host/search : Path 또는 End point/로 구분됨.?q=android: ParameterGET /search?q=android HTTP/1.1
Host: google.com
Cache-Control:no-cache
Accept: text/html, application/xhtml+xml ...
Accept-Language: en
...
GET : HTTP Method 중 하나/search?q=android : end pointHost: google.com : HostHTTP/1.1 : HTTP versionCache-Control:no-cache, Accept: text/html, application/xhtml+xml..., Accept-Language: en : headerClient가 무엇을 수행하려고 하는 지를 서버에게 알리는 HTTP Method.
Client가 바라는 정확한 resource를 가리키는 end point 명시하는 method.
? 뒤에 이런 parameter가 더해짐.& (ampersnad)로 각각이 구분됨.Server에 새로운 resource를 생성(Create)할 때 사용하는 HTTP Method.
어떤 데이터 전체를 다른 데이터로 변경하는 HTTP Method.
Server의 특정한 데이터를 삭제(Delete)하는 HTTP Method.
Server가 request에 대한 처리를 끝낸 후 Client에게 HTTP Response를 보냄.
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Content-Encoding: br
Date: Fri, 12 Feb 2021 01:59:01 GMT
Server: gws
Cache-Control: private, max-age=0
...
<!DOCTYPE html> ...
Content-Type: text/html; charset=UTF-8 : Content-TypeContent-Encoding: ~ max-age=0 : 다른 header들.<!DOCTYPE html> ... : 실제 내용(content)자주 쓰이는 status code들. 기대한대로 프로그램이 동작하지 않을 때 status code를 참고하면 어디서부터 문제를 찾기 시작해야 하는 지 알 수 있음.
아래의 원칙을 준수하는 것.
- Client-Server architecture
- Client와 Server 간의 명확한 관심사 분리(Seperation of Concern)가 이루어진 구조를 따른다.
- Client는 Request만 보내고, Server는 그에 따른 Response만 보낸다.
- Resources exposed as URIs
- Server에 있는 resource는 URI(Uniform Resource Identifier)를 통해 식별된다.
- Uniform interface
- resource를 Create, Get, Update, Delete 연산을 통해 다룬다.
- Stateless
- Request간의 Client의 state를 기억할 필요가 없어야 한다.
- 모든 Client Request는 Server가 해당 Request를 처리하기 위한 모든 정보를 포함하고 있어야 한다.
위의 4가지는 기본적인 원칙. 이 외에 RESTful을 위한 특징이 더 있긴 함.