[ 설치 ]
라이브러리 설치 명령어
npm install axios
package.json 추가 작성
"type" : "module"
fetch
와 다르게 응답 데이터를 객체 데이터로 자동으로 변환.
Promise 방식
function getPosts(url) {
axios
.get(url) // url에 요청
.then((response) => {
console.log(response); // 응답 데이터 출력
})
.catch((error) => console.error(`에러: ${error}`)); // 실패 시 에러 출력
}
getPosts(`https://jsonplaceholder.typicode.com/posts/1`);
async/await 방식
async function getPosts(url) {
try {
const response = await axios.get(url); // url에 요청
console.log(response); // 응답 데이터 출력
} catch (error) {
console.error(`에러: ${error}`); // 실패 시 에러 출력
}
}
getPosts(`https://jsonplaceholder.typicode.com/posts/1`);
기본 코드
import axios from "axios"; // axios 사용 선언
const BASE_URL = `https://dummyjson.com`;
async function fetchData() {
const res = await axios.get(`${BASE_URL}/...`);
const data = res["data"];
console.log(data);
}
fetchData();
import axios from "axios"; // axios 사용 선언
const BASE_URL = `https://dummyjson.com`; // 실습에 참고할 URL
1번 문제
// TODO: 모든 장바구니 목록 조회(Get all carts)
// 아래 요구사항을 참고하여 코드를 작성한다
// 1. 모든 장바구니 조회(Get all carts) 요청
// 2. 응답 데이터 객체 출력
async function getAllCarts() {
const response = await axios.get(`${BASE_URL}/carts`);
const data = response["data"];
console.log(data);
}
getAllCarts();
response 변수
: https://dummyjson.com/carts
페이지의 모든 데이터를 요청하고, 그에 대한 응답을 받는다.
data 변수
: response
변수에 할당된 수많은 데이터 중, 카트의 상품 정보 리스트 데이터가 저장된다.
2번 문제
// TODO: 단일 장바구니 조회(Get a single cart)
// 아래 요구사항을 참고하여 코드를 작성한다
// 1. 10번 장바구니 조회(Get a single cart) 요청
// 2. 응답 데이터 객체 출력
async function getASingleCart(id) {
const response = await axios.get(`${BASE_URL}/carts/${id}`);
const data = response["data"];
console.log(data);
}
getASingleCart(10);
response 변수
getASingleCart()
함수 호출의 인자를 통해 전달된 10이 ${BASE_URL}/carts/${id}
라는 URL의 path
값으로 할당된다.
결론적으로 id가 10번인 카트의 모든 데이터를 응답 받는다.
3번 문제
// TODO: 단일 장바구니에 포함된 상품의 이름 추출 및 출력
// 아래 요구사항을 참고하여 코드를 작성한다
// 1. 10번 장바구니 조회(Get a single cart) 요청
// 2. 응답 데이터 객체에서 상품의 목록(products) 배열 데이터 추출
// 3. map() 메서드를 활용해서 배열 데이터에서 상품의 이름만 모아서 새로운 배열 생성
// 4. 상품의 이름만 모은 배열 출력
async function getASingleCart(id) {
const response = await axios.get(`${BASE_URL}/carts/${id}`);
const products = response["data"]["products"];
const newArr = products.map((product) => {
return product["title"];
});
console.log(newArr);
}
getASingleCart(10);
products 변수
: id가 10인 카트에 들어 있는 상품 배열이 할당 된다.
newArr 변수
: products
배열 변수에 할당된 각 요소(상품)에 대한 이름 배열이 만들어져 할당 된다.
위의 실습 예시에서 사용된 변수에 할당된 값은 다음과 같다.
1번 문제 - const response 변수
{
status: 200,
statusText: 'OK',
headers: Object [AxiosHeaders] {
date: 'Tue, 23 Sep 2025 08:48:28 GMT',
'content-type': 'application/json; charset=utf-8',
'transfer-encoding': 'chunked',
connection: 'keep-alive',
server: 'cloudflare',
'x-ratelimit-limit': '100',
'x-ratelimit-remaining': '99',
'x-ratelimit-reset': '1758617309',
'x-dns-prefetch-control': 'off',
'x-frame-options': 'SAMEORIGIN',
'strict-transport-security': 'max-age=15552000; includeSubDomains',
'x-download-options': 'noopen',
'x-content-type-options': 'nosniff',
'x-xss-protection': '1; mode=block',
'access-control-allow-origin': '*',
'x-powered-by': 'Cats on Keyboards',
etag: 'W/"7d39-+rQ7kyHBCLIn9tjTeKVf4oegWkQ"',
vary: 'Accept-Encoding',
'cf-cache-status': 'DYNAMIC',
nel: '{"report_to":"cf-nel","success_fraction":0.0,"max_age":604800}',
'report-to': '{"group":"cf-nel","max_age":604800,"endpoints":[{"url":"https://a.nel.cloudflare.com/report/v4?s=8CkguI7QPaztZ%2FANstC%2Bkgw7WftQR5fYqsaRzph8nWO2M4oPXk70B2%2BYzMJAT5ra1gH3sOLpMwfhlLYeeM1IVrNXLrrIbVWyO2jvxCk%3D"}]}',
'cf-ray': '9838c87f1c2d8d06-KIX'
},
config: {
transitional: {
silentJSONParsing: true,
forcedJSONParsing: true,
clarifyTimeoutError: false
},
adapter: [ 'xhr', 'http', 'fetch' ],
transformRequest: [ [Function: transformRequest] ],
transformResponse: [ [Function: transformResponse] ],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
env: { FormData: [Function [FormData]], Blob: [class Blob] },
validateStatus: [Function: validateStatus],
headers: Object [AxiosHeaders] {
Accept: 'application/json, text/plain, */*',
'Content-Type': undefined,
'User-Agent': 'axios/1.12.2',
'Accept-Encoding': 'gzip, compress, deflate, br'
},
method: 'get',
url: 'https://dummyjson.com/carts',
allowAbsoluteUrls: true,
data: undefined
},
request: <ref *1> ClientRequest {
_events: [Object: null prototype] {
abort: [Function (anonymous)],
aborted: [Function (anonymous)],
connect: [Function (anonymous)],
error: [Function (anonymous)],
socket: [Function (anonymous)],
timeout: [Function (anonymous)],
finish: [Function: requestOnFinish]
},
_eventsCount: 7,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: true,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: true,
maxRequestsOnConnectionReached: false,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
strictContentLength: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
_closed: true,
_header: 'GET /carts HTTP/1.1\r\n' +
'Accept: application/json, text/plain, */*\r\n' +
'User-Agent: axios/1.12.2\r\n' +
'Accept-Encoding: gzip, compress, deflate, br\r\n' +
'Host: dummyjson.com\r\n' +
'Connection: keep-alive\r\n' +
'\r\n',
_keepAliveTimeout: 0,
_onPendingData: [Function: nop],
agent: Agent {
_events: [Object: null prototype],
_eventsCount: 2,
_maxListeners: undefined,
defaultPort: 443,
protocol: 'https:',
options: [Object: null prototype],
requests: [Object: null prototype] {},
sockets: [Object: null prototype] {},
freeSockets: [Object: null prototype],
keepAliveMsecs: 1000,
keepAlive: true,
maxSockets: Infinity,
maxFreeSockets: 256,
scheduling: 'lifo',
maxTotalSockets: Infinity,
totalSocketCount: 1,
maxCachedSessions: 100,
_sessionCache: [Object],
[Symbol(shapeMode)]: false,
[Symbol(kCapture)]: false
},
socketPath: undefined,
method: 'GET',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
joinDuplicateHeaders: undefined,
path: '/carts',
_ended: true,
res: IncomingMessage {
_events: [Object],
_readableState: [ReadableState],
_maxListeners: undefined,
socket: null,
httpVersionMajor: 1,
httpVersionMinor: 1,
httpVersion: '1.1',
complete: true,
rawHeaders: [Array],
rawTrailers: [],
joinDuplicateHeaders: undefined,
aborted: false,
upgrade: false,
url: '',
method: null,
statusCode: 200,
statusMessage: 'OK',
client: [TLSSocket],
_consuming: true,
_dumped: false,
req: [Circular *1],
_eventsCount: 4,
responseUrl: 'https://dummyjson.com/carts',
redirects: [],
[Symbol(shapeMode)]: true,
[Symbol(kCapture)]: false,
[Symbol(kHeaders)]: [Object],
[Symbol(kHeadersCount)]: 46,
[Symbol(kTrailers)]: null,
[Symbol(kTrailersCount)]: 0
},
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
host: 'dummyjson.com',
protocol: 'https:',
_redirectable: Writable {
_events: [Object],
_writableState: [WritableState],
_maxListeners: undefined,
_options: [Object],
_ended: true,
_ending: true,
_redirectCount: 0,
_redirects: [],
_requestBodyLength: 0,
_requestBodyBuffers: [],
_eventsCount: 3,
_onNativeResponse: [Function (anonymous)],
_currentRequest: [Circular *1],
_currentUrl: 'https://dummyjson.com/carts',
[Symbol(shapeMode)]: true,
[Symbol(kCapture)]: false
},
[Symbol(shapeMode)]: false,
[Symbol(kCapture)]: false,
[Symbol(kBytesWritten)]: 0,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kChunkedBuffer)]: [],
[Symbol(kChunkedLength)]: 0,
[Symbol(kSocket)]: TLSSocket {
_tlsOptions: [Object],
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
secureConnecting: false,
_SNICallback: null,
servername: 'dummyjson.com',
alpnProtocol: false,
authorized: true,
authorizationError: null,
encrypted: true,
_events: [Object: null prototype],
_eventsCount: 9,
connecting: false,
_hadError: false,
_parent: null,
_host: 'dummyjson.com',
_closeAfterHandlingError: false,
_readableState: [ReadableState],
_writableState: [WritableState],
allowHalfOpen: false,
_maxListeners: undefined,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: undefined,
_server: null,
ssl: [TLSWrap],
_requestCert: true,
_rejectUnauthorized: true,
timeout: 5000,
parser: null,
_httpMessage: null,
autoSelectFamilyAttemptedAddresses: [Array],
[Symbol(alpncallback)]: null,
[Symbol(res)]: [TLSWrap],
[Symbol(verified)]: true,
[Symbol(pendingSession)]: null,
[Symbol(async_id_symbol)]: -1,
[Symbol(kHandle)]: [TLSWrap],
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: Timeout {
_idleTimeout: 5000,
_idlePrev: [TimersList],
_idleNext: [TimersList],
_idleStart: 443,
_onTimeout: [Function: bound ],
_timerArgs: undefined,
_repeat: null,
_destroyed: false,
[Symbol(refed)]: false,
[Symbol(kHasPrimitive)]: false,
[Symbol(asyncId)]: 42,
[Symbol(triggerId)]: 40,
[Symbol(kAsyncContextFrame)]: undefined
},
[Symbol(kBuffer)]: null,
[Symbol(kBufferCb)]: null,
[Symbol(kBufferGen)]: null,
[Symbol(shapeMode)]: true,
[Symbol(kCapture)]: false,
[Symbol(kSetNoDelay)]: false,
[Symbol(kSetKeepAlive)]: true,
[Symbol(kSetKeepAliveInitialDelay)]: 1,
[Symbol(kBytesRead)]: 0,
[Symbol(kBytesWritten)]: 0,
[Symbol(connect-options)]: [Object]
},
[Symbol(kOutHeaders)]: [Object: null prototype] {
accept: [Array],
'user-agent': [Array],
'accept-encoding': [Array],
host: [Array]
},
[Symbol(errored)]: null,
[Symbol(kHighWaterMark)]: 65536,
[Symbol(kRejectNonStandardBodyWrites)]: false,
[Symbol(kUniqueHeaders)]: null
},
data: {
carts: [
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object]
],
total: 50,
skip: 0,
limit: 30
}
}
1번 문제 - const data 변수
{
carts: [
{
id: 1,
products: [Array],
total: 103774.85,
discountedTotal: 89686.65,
userId: 33,
totalProducts: 4,
totalQuantity: 15
},
{
id: 2,
products: [Array],
total: 4794.8,
discountedTotal: 4288.95,
userId: 142,
totalProducts: 5,
totalQuantity: 20
},
{
id: 3,
products: [Array],
total: 16775.87,
discountedTotal: 14144.3,
userId: 108,
totalProducts: 5,
totalQuantity: 13
},
{
id: 4,
products: [Array],
total: 456.83,
discountedTotal: 443.23,
userId: 87,
totalProducts: 4,
totalQuantity: 17
},
{
id: 5,
products: [Array],
total: 7431.3,
discountedTotal: 6676.44,
userId: 134,
totalProducts: 6,
totalQuantity: 20
},
{
id: 6,
products: [Array],
total: 35199.86,
discountedTotal: 31435.05,
userId: 150,
totalProducts: 4,
totalQuantity: 14
},
{
id: 7,
products: [Array],
total: 145651.89,
discountedTotal: 128504.41,
userId: 86,
totalProducts: 3,
totalQuantity: 11
},
{
id: 8,
products: [Array],
total: 15685.86,
discountedTotal: 12666.75,
userId: 23,
totalProducts: 4,
totalQuantity: 14
},
{
id: 9,
products: [Array],
total: 65529.87,
discountedTotal: 63336.57,
userId: 194,
totalProducts: 4,
totalQuantity: 13
},
{
id: 10,
products: [Array],
total: 29499.92,
discountedTotal: 25675.13,
userId: 160,
totalProducts: 2,
totalQuantity: 8
},
{
id: 11,
products: [Array],
total: 568.36,
discountedTotal: 476.76,
userId: 172,
totalProducts: 6,
totalQuantity: 14
},
{
id: 12,
products: [Array],
total: 931.91,
discountedTotal: 798.02,
userId: 202,
totalProducts: 2,
totalQuantity: 9
},
{
id: 13,
products: [Array],
total: 793.07,
discountedTotal: 750.8,
userId: 41,
totalProducts: 5,
totalQuantity: 13
},
{
id: 14,
products: [Array],
total: 586.82,
discountedTotal: 500.25,
userId: 94,
totalProducts: 6,
totalQuantity: 18
},
{
id: 15,
products: [Array],
total: 11741.31,
discountedTotal: 10940.95,
userId: 11,
totalProducts: 5,
totalQuantity: 19
},
{
id: 16,
products: [Array],
total: 172.24,
discountedTotal: 155.84,
userId: 200,
totalProducts: 3,
totalQuantity: 6
},
{
id: 17,
products: [Array],
total: 192.87,
discountedTotal: 173.9,
userId: 141,
totalProducts: 4,
totalQuantity: 13
},
{
id: 18,
products: [Array],
total: 1464.78,
discountedTotal: 1257.94,
userId: 189,
totalProducts: 6,
totalQuantity: 22
},
{
id: 19,
products: [Array],
total: 933.87,
discountedTotal: 794.78,
userId: 59,
totalProducts: 4,
totalQuantity: 13
},
{
id: 20,
products: [Array],
total: 3534.78,
discountedTotal: 2936.58,
userId: 90,
totalProducts: 6,
totalQuantity: 22
},
{
id: 21,
products: [Array],
total: 251.96,
discountedTotal: 245.68,
userId: 42,
totalProducts: 2,
totalQuantity: 4
},
{
id: 22,
products: [Array],
total: 222.88,
discountedTotal: 205.63,
userId: 140,
totalProducts: 4,
totalQuantity: 12
},
{
id: 23,
products: [Array],
total: 7757.8,
discountedTotal: 7439.98,
userId: 147,
totalProducts: 5,
totalQuantity: 20
},
{
id: 24,
products: [Array],
total: 1749.9,
discountedTotal: 1594.33,
userId: 6,
totalProducts: 3,
totalQuantity: 10
},
{
id: 25,
products: [Array],
total: 412.98,
discountedTotal: 353.55,
userId: 118,
totalProducts: 2,
totalQuantity: 2
},
{
id: 26,
products: [Array],
total: 459.92,
discountedTotal: 441.17,
userId: 66,
totalProducts: 2,
totalQuantity: 8
},
{
id: 27,
products: [Array],
total: 190.89,
discountedTotal: 170.95,
userId: 75,
totalProducts: 4,
totalQuantity: 11
},
{
id: 28,
products: [Array],
total: 209.91,
discountedTotal: 186.09,
userId: 147,
totalProducts: 2,
totalQuantity: 9
},
{
id: 29,
products: [Array],
total: 3862.43,
discountedTotal: 3488.44,
userId: 170,
totalProducts: 5,
totalQuantity: 17
},
{
id: 30,
products: [Array],
total: 128249.07,
discountedTotal: 118740.76,
userId: 177,
totalProducts: 4,
totalQuantity: 13
}
],
total: 50,
skip: 0,
limit: 30
}
mymacui-MacBookA
2번 문제 - const response 변수
{
status: 200,
statusText: 'OK',
headers: Object [AxiosHeaders] {
date: 'Tue, 23 Sep 2025 08:54:19 GMT',
'content-type': 'application/json; charset=utf-8',
'transfer-encoding': 'chunked',
connection: 'keep-alive',
server: 'cloudflare',
'x-ratelimit-limit': '100',
'x-ratelimit-remaining': '99',
'x-ratelimit-reset': '1758617662',
'x-dns-prefetch-control': 'off',
'x-frame-options': 'SAMEORIGIN',
'strict-transport-security': 'max-age=15552000; includeSubDomains',
'x-download-options': 'noopen',
'x-content-type-options': 'nosniff',
'x-xss-protection': '1; mode=block',
'access-control-allow-origin': '*',
'x-powered-by': 'Cats on Keyboards',
etag: 'W/"290-hLR7H7pVJPVmnjdJHH8foJBTjKg"',
vary: 'Accept-Encoding',
'cf-cache-status': 'DYNAMIC',
nel: '{"report_to":"cf-nel","success_fraction":0.0,"max_age":604800}',
'report-to': '{"group":"cf-nel","max_age":604800,"endpoints":[{"url":"https://a.nel.cloudflare.com/report/v4?s=okFIhH0hIOA6KiNqgSLJQgtEAa2KKwed57b0DvXDb7Aa0eC8YLoTb6Mh9YVJ6xhlBfkTw5C960q%2FUt6GKapFx%2FMAbKXFG0RIjgAyaco%3D"}]}',
'cf-ray': '9838d10edac08373-KIX'
},
config: {
transitional: {
silentJSONParsing: true,
forcedJSONParsing: true,
clarifyTimeoutError: false
},
adapter: [ 'xhr', 'http', 'fetch' ],
transformRequest: [ [Function: transformRequest] ],
transformResponse: [ [Function: transformResponse] ],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
env: { FormData: [Function [FormData]], Blob: [class Blob] },
validateStatus: [Function: validateStatus],
headers: Object [AxiosHeaders] {
Accept: 'application/json, text/plain, */*',
'Content-Type': undefined,
'User-Agent': 'axios/1.12.2',
'Accept-Encoding': 'gzip, compress, deflate, br'
},
method: 'get',
url: 'https://dummyjson.com/carts/10',
allowAbsoluteUrls: true,
data: undefined
},
request: <ref *1> ClientRequest {
_events: [Object: null prototype] {
abort: [Function (anonymous)],
aborted: [Function (anonymous)],
connect: [Function (anonymous)],
error: [Function (anonymous)],
socket: [Function (anonymous)],
timeout: [Function (anonymous)],
finish: [Function: requestOnFinish]
},
_eventsCount: 7,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: true,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: true,
maxRequestsOnConnectionReached: false,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
strictContentLength: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
_closed: true,
_header: 'GET /carts/10 HTTP/1.1\r\n' +
'Accept: application/json, text/plain, */*\r\n' +
'User-Agent: axios/1.12.2\r\n' +
'Accept-Encoding: gzip, compress, deflate, br\r\n' +
'Host: dummyjson.com\r\n' +
'Connection: keep-alive\r\n' +
'\r\n',
_keepAliveTimeout: 0,
_onPendingData: [Function: nop],
agent: Agent {
_events: [Object: null prototype],
_eventsCount: 2,
_maxListeners: undefined,
defaultPort: 443,
protocol: 'https:',
options: [Object: null prototype],
requests: [Object: null prototype] {},
sockets: [Object: null prototype] {},
freeSockets: [Object: null prototype],
keepAliveMsecs: 1000,
keepAlive: true,
maxSockets: Infinity,
maxFreeSockets: 256,
scheduling: 'lifo',
maxTotalSockets: Infinity,
totalSocketCount: 1,
maxCachedSessions: 100,
_sessionCache: [Object],
[Symbol(shapeMode)]: false,
[Symbol(kCapture)]: false
},
socketPath: undefined,
method: 'GET',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
joinDuplicateHeaders: undefined,
path: '/carts/10',
_ended: true,
res: IncomingMessage {
_events: [Object],
_readableState: [ReadableState],
_maxListeners: undefined,
socket: null,
httpVersionMajor: 1,
httpVersionMinor: 1,
httpVersion: '1.1',
complete: true,
rawHeaders: [Array],
rawTrailers: [],
joinDuplicateHeaders: undefined,
aborted: false,
upgrade: false,
url: '',
method: null,
statusCode: 200,
statusMessage: 'OK',
client: [TLSSocket],
_consuming: true,
_dumped: false,
req: [Circular *1],
_eventsCount: 4,
responseUrl: 'https://dummyjson.com/carts/10',
redirects: [],
[Symbol(shapeMode)]: true,
[Symbol(kCapture)]: false,
[Symbol(kHeaders)]: [Object],
[Symbol(kHeadersCount)]: 46,
[Symbol(kTrailers)]: null,
[Symbol(kTrailersCount)]: 0
},
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
host: 'dummyjson.com',
protocol: 'https:',
_redirectable: Writable {
_events: [Object],
_writableState: [WritableState],
_maxListeners: undefined,
_options: [Object],
_ended: true,
_ending: true,
_redirectCount: 0,
_redirects: [],
_requestBodyLength: 0,
_requestBodyBuffers: [],
_eventsCount: 3,
_onNativeResponse: [Function (anonymous)],
_currentRequest: [Circular *1],
_currentUrl: 'https://dummyjson.com/carts/10',
[Symbol(shapeMode)]: true,
[Symbol(kCapture)]: false
},
[Symbol(shapeMode)]: false,
[Symbol(kCapture)]: false,
[Symbol(kBytesWritten)]: 0,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kChunkedBuffer)]: [],
[Symbol(kChunkedLength)]: 0,
[Symbol(kSocket)]: TLSSocket {
_tlsOptions: [Object],
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
secureConnecting: false,
_SNICallback: null,
servername: 'dummyjson.com',
alpnProtocol: false,
authorized: true,
authorizationError: null,
encrypted: true,
_events: [Object: null prototype],
_eventsCount: 9,
connecting: false,
_hadError: false,
_parent: null,
_host: 'dummyjson.com',
_closeAfterHandlingError: false,
_readableState: [ReadableState],
_writableState: [WritableState],
allowHalfOpen: false,
_maxListeners: undefined,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: undefined,
_server: null,
ssl: [TLSWrap],
_requestCert: true,
_rejectUnauthorized: true,
timeout: 5000,
parser: null,
_httpMessage: null,
autoSelectFamilyAttemptedAddresses: [Array],
[Symbol(alpncallback)]: null,
[Symbol(res)]: [TLSWrap],
[Symbol(verified)]: true,
[Symbol(pendingSession)]: null,
[Symbol(async_id_symbol)]: -1,
[Symbol(kHandle)]: [TLSWrap],
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: Timeout {
_idleTimeout: 5000,
_idlePrev: [TimersList],
_idleNext: [TimersList],
_idleStart: 845,
_onTimeout: [Function: bound ],
_timerArgs: undefined,
_repeat: null,
_destroyed: false,
[Symbol(refed)]: false,
[Symbol(kHasPrimitive)]: false,
[Symbol(asyncId)]: 32,
[Symbol(triggerId)]: 30,
[Symbol(kAsyncContextFrame)]: undefined
},
[Symbol(kBuffer)]: null,
[Symbol(kBufferCb)]: null,
[Symbol(kBufferGen)]: null,
[Symbol(shapeMode)]: true,
[Symbol(kCapture)]: false,
[Symbol(kSetNoDelay)]: false,
[Symbol(kSetKeepAlive)]: true,
[Symbol(kSetKeepAliveInitialDelay)]: 1,
[Symbol(kBytesRead)]: 0,
[Symbol(kBytesWritten)]: 0,
[Symbol(connect-options)]: [Object]
},
[Symbol(kOutHeaders)]: [Object: null prototype] {
accept: [Array],
'user-agent': [Array],
'accept-encoding': [Array],
host: [Array]
},
[Symbol(errored)]: null,
[Symbol(kHighWaterMark)]: 65536,
[Symbol(kRejectNonStandardBodyWrites)]: false,
[Symbol(kUniqueHeaders)]: null
},
data: {
id: 10,
products: [ [Object], [Object] ],
total: 29499.92,
discountedTotal: 25675.13,
userId: 160,
totalProducts: 2,
totalQuantity: 8
}
}
2번 문제 - const data 변수
{
id: 10,
products: [
{
id: 190,
title: 'IWC Ingenieur Automatic Steel',
price: 4999.99,
quantity: 5,
total: 24999.949999999997,
discountPercentage: 12.34,
discountedTotal: 21914.96,
thumbnail: 'https://cdn.dummyjson.com/products/images/womens-watches/IWC%20Ingenieur%20Automatic%20Steel/thumbnail.png'
},
{
id: 94,
title: 'Longines Master Collection',
price: 1499.99,
quantity: 3,
total: 4499.97,
discountPercentage: 16.44,
discountedTotal: 3760.17,
thumbnail: 'https://cdn.dummyjson.com/products/images/mens-watches/Longines%20Master%20Collection/thumbnail.png'
}
],
total: 29499.92,
discountedTotal: 25675.13,
userId: 160,
totalProducts: 2,
totalQuantity: 8
}
3번 문제 - const response 변수
3번 문제 - const products 변수
[
{
id: 190,
title: 'IWC Ingenieur Automatic Steel',
price: 4999.99,
quantity: 5,
total: 24999.949999999997,
discountPercentage: 12.34,
discountedTotal: 21914.96,
thumbnail: 'https://cdn.dummyjson.com/products/images/womens-watches/IWC%20Ingenieur%20Automatic%20Steel/thumbnail.png'
},
{
id: 94,
title: 'Longines Master Collection',
price: 1499.99,
quantity: 3,
total: 4499.97,
discountPercentage: 16.44,
discountedTotal: 3760.17,
thumbnail: 'https://cdn.dummyjson.com/products/images/mens-watches/Longines%20Master%20Collection/thumbnail.png'
}
]
3번 문제 - const products 변수
[ 'IWC Ingenieur Automatic Steel', 'Longines Master Collection' ]