NodeJS(4기) 44일차

형집·2023년 1월 14일

NodeJS(4기)

목록 보기
49/56
post-thumbnail

client가 server에 요청을 함
데이터를 header와 body 에 담아서 보낸다.

1.url로 보내기

QueryString

url 끝에 ?를 기준으로 뒤에 존재하는 값들
ex1)https://search.naver.com/search.naver?where=nexearch&sm=top_hty&fbm=1&ie=utf8&query=nodejs
ex2)https://search.naver.com/search.naver?where=nexearch&sm=top_sly.hst&fbm=1&acr=1&acq=javas&qdt=0&ie=utf8&query=javascript
여러개의 값을 보낼 때에는 &으로 구분

app.get("/query",(req,res)=>{
    console.log("query:",req.query);
    res.send('/요청했음');
})

Path Param

app.get("/pathparam/:id",(req,res)=>{
    console.log("params:",req.params);
    res.send('/요청했음');
})


2.헤더로 보내기

헤더

app.get("/header",(req,res)=>{
    console.log("headers:",req.headers);
    res.send('/요청했음');
})

쿠키

app.get("/cookie",(req,res)=>{
    console.log("cookies:",req.cookies);
    res.send('/요청했음');
});


3.바디로 보내기

바디값 가져오기

app.get("/body",(req,res)=>{
    console.log("body:",req.body,typeof(req.body));
    res.send('/요청했음')
})

profile
개발자

0개의 댓글