스프링 부트, 입문!

스프링 부트, 입문!

쉽고 빠르게 배우는, 스프링 부트 첫걸음!

18 REST API와 JSON

# REST API와 JSON ## 미션 REST API의 개념과 동작 흐름을 분석하시오. ![홍팍-스프링-부트-입문--미션](http://drive.google.com/uc?export=view&id=1e3FuGtDfy36bwtA4U5J1zMxufGHOO9Qr) ## 07:34 GET 요청과 응답 성공 - Status Code 200, OK #### 게시글 목록 요청 ``` GET https://jsonplaceholder.typicode.com/posts ``` #### 1번 게시글 상세 요청 ``` GET https://jsonplaceholder.typicode.com/posts/1 ``` ## 09:11 GET 요청과 응답 실패 - Status Code 404, Not Found #### 존재하지 않는 게시글 요청 ``` GET https://jsonplaceholder.typicode.com/posts/101 ``` ## 10:11 HTTP 요청과 응답 분석 - http header, http body #### HTTP 분석 ``` GET /posts/101 HTTP/1.1 Host: jsonplaceholder.typicode.com HTTP/1.1 404 date: Fri, 22 Apr 2022 11:25:38 GMT content-type: application/json; charset=utf-8 content-length: 2 x-powered-by: Express x-ratelimit-limit: 1000 x-ratelimit-remaining: 999 x-ratelimit-reset: 1650626787 vary: Origin, Accept-Encoding access-control-allow-credentials: true cache-control: max-age=43200 pragma: no-cache expires: -1 x-content-type-options: nosniff etag: W/"2-vyGp6PvFo4RvsFtPoIWeCReyIC8" via: 1.1 vegur cf-cache-status: MISS expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=nlSvnyRvizeJezp%2FuamEsuKMfkjcfbL39VakxznvU4QQLvaegKBiiRr8z7OYpPraCD5PS3Uk2HG3ZpOTH96SXXWHCDQimXIpds41kOTNjxsxzEnWzo0F3Y6F5Ltc4sD%2FLZyNb5l7m9rM%2F27DbjTn"}],"group":"cf-nel","max_age":604800} nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800} server: cloudflare cf-ray: 6ffdfff84eeef8b3-NRT alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400 {} ``` ## 12:07 POST 요청과 응답 성공 - Status Code 201, Created #### 새 게시글 생성 요청 ``` POST https://jsonplaceholder.typicode.com/posts { "title": "오늘은 왠지..", "body": "치킨을 먹고 싶어라..!" } ``` ## 13:56 POST 요청과 응답 에러 - Status Code 500, Internal Server Error #### 잘못된 새 게시글 요청 ``` POST https://jsonplaceholder.typicode.com/posts { title: "오늘은 왠지..", body: "치킨을 먹고 싶어라..!" } ``` ## 15:13 PATCH 요청과 응답 #### 게시글 수정 요청 ``` PATCH https://jsonplaceholder.typicode.com/posts/1 { "title": "asdfasdfadf", "body": "123123123" } ``` ## 16:13 DELETE 요청과 응답 #### 게시글 삭제 요청 ``` DELETE https://jsonplaceholder.typicode.com/posts/10 ``` ## 🔥 구글링 훈련하기 - REST API란 - HTTP 메소드 - HTTP 상태 코드 - HTTP 요청 응답 - HTTP 메시지 구조