Node.js

THE REST API

don_Kim 2021. 4. 29. 17:05

Representational State Transfer - Application Programming Interface (REST API or RESTful API)

 

CRUD

OPERATION METHOD PATH
Create POST /api/products
Read GET /api/products
Read GET /api/products/:id
Update PATCH /api/products/:id
Delete DELETE /api/products/:id

 

서버로 요청(Request) 그리고 서버가 응답(Response)할 때 보내지는 HTTP request&response의 기본구조

HTTP REQUEST
POST /products HTTP/1.1
Headers key-value pairs
Accept: application/json expecting JSON data back from the server
Connection: Keep-Alive  
Authorization: Bearer aejiofj2IenjaNeiaddkJ... to setup authentication
{ "Shoes" : "Adidas", "qty" : 20} 실제 보내는 JSON data (신발 : 아디다스, 갯수: 20)라는 프로덕트를 만들어 달라
Response
HTTP/1.1 201 Created
Headers key-value pairs
Date: Sun,  28 Jul 2021 15:37:23 PST 언제 응답했는지 표기
Server: Express to setup authentication
Content-Type: application/json Meta type
{ "_id" : "5c123ead003dab12", "Shoes" : "Adidas", "qty" : 20} DB에 저장되고나서 그 정보를 다시 클라이언트로 보내준다