Request & Response

PussinSocks·2022년 7월 18일
0

CloneCoding

목록 보기
4/20

HTTP

  • A way servers communicate with users, or servers communicate with each other.

GET

  • A HTTP method, a type of Request
  • For example, when a user try to go to a website, browser request to server, and the browser GETs the website to the user.
  • User not making the HTTP request, browser makes request for user.

Handling server to respond to GET request

const callbackFunction = () => { function }
app.get("/route", callbackFunction);

I think easiest way to think "/route" is a path or a directory

Just like in the JavaScript, where addEventListener put event object in the function,

function handleClikc(event){
	"some function";
}
btn.addEventListener("click", handleClick);

Express will insert objects to the callback function. and this is reqeust(or req) and response(or res).

const callbackFunction = (req, res) => { 
	res.send("Hello World");
}

Short summary

  • While a server is listening, browser can ask request( GET request in this time)
  • When the server see the request, then server will reply to the browser with res object and properties.
  • Then browser GETs the response and upload on the browser.
profile
On a journey to be a front-end developer

0개의 댓글