티스토리 뷰

자바스크립트

Nodejs ) 서버 Express.js req, res , POST, GET, Route 개념 정리

YG - 96년생 , 강아지 있음, 개발자 희망 2021. 5. 16. 09:00

GET

단순히 페이지를 가져오는 것.

 

GET request >> URL에 접근하는 것

  • URL을 쓴다 (naver.com) >> 브라우저가 GET method를  실행한다 >> 브라우저가 URL의 페이지를 읽어온다

 

GET request => URL에 접근
- URL을 쓴다(youtube.com) => 브라우저가 GET method를 실행한다 => 브라우저가 URL의 페이지를 읽어온다

POST

정보를 전달하는 것.

 

  • 웹사이트에 Login 한다 => 브라우저가 POST method 실행한다. => 브라우저가 웹사이트에 정보를 전달한다.

 

 

 

req(request 요청하다)

The req object represents the HTTP request and has properties for the request query string, parameters, body, HTTP headers, and so on. In this documentation and by convention, the object is always referred to as req (and the HTTP response is res) but its actual name is determined by the parameters to the callback function in which you’re working.

 

req 개체는 HTTP 요청을 나타내며 요청 쿼리 문자열, 매개 변수, 본문, HTTP 헤더 등에 대한 속성을 가집니다. 이 설명서 및 관례상 개체는 항상 req(그리고 HTTP 응답은 res)로 표시되지만 실제 이름은 작업 중인 콜백 함수에 대한 매개 변수에 의해 결정됩니다.

 

expressjs.com/ko/api.html#req

 

POST 로 전달한 정보를 요청해서, 정보를 받음 !

 

req obj : 누군가 정보를 얻고자 페이지를 요청했을때, 어떤 종류의 데이터가 페이지로 전송됐는지 확인할때 request object를 이용한다. 예를 들어 이 URL에 POST 방식으로 아이디와 패스워드를 전송한다면, 이렇게 app.post로 아이디랑 패스워드를 보낸다면 서버에는 request object로 정보를 얻을 수 있다.

 

res(Response 대응하다)

 

 

The res object represents the HTTP response that an Express app sends when it gets an HTTP request.

In this documentation and by convention, the object is always referred to as res (and the HTTP request is req) but its actual name is determined by the parameters to the callback function in which you’re working.

 

res 개체는 Express 앱이 HTTP 요청을 받을 때 보내는 HTTP 응답을 나타냅니다.

이 설명서 및 관례에 따라 개체를 항상 res(그리고 HTTP 요청은 req)라고 부르지만 실제 이름은 작업 중인 콜백 함수에 대한 매개 변수에 의해 결정됩니다.

 

expressjs.com/ko/api.html#res

 

Express 4.x - API 참조

Express 4.x API express() Creates an Express application. The express() function is a top-level function exported by the express module. var express = require('express') var app = express() Methods express.json([options]) This middleware is available in Ex

expressjs.com

 

 

 

정보를 응답! ( res.send )

 

res obj => POST한 사람의 정보를 받아서 보내주는 역할을 한다.

 

Router

 

A router object is an isolated instance of middleware and routes. You can think of it as a “mini-application,” capable only of performing middleware and routing functions. Every Express application has a built-in app router.

A router behaves like middleware itself, so you can use it as an argument to app.use() or as the argument to another router’s use() method.

The top-level express object has a Router() method that creates a new router object.

Once you’ve created a router object, you can add middleware and HTTP method routes (such as get, put, post, and so on) to it just like an application.

 

 

라우터 개체는 미들웨어 및 라우트의 분리된 인스턴스입니다. 미들웨어 및 라우팅 기능만 수행할 수 있는 "미니 애플리케이션"이라고 생각할 수 있습니다. 모든 Express 응용 프로그램에는 앱 라우터가 내장되어 있습니다.

라우터는 미들웨어 자체와 같이 동작하므로 app.use()에 대한 인수로 사용하거나 다른 라우터의 use() 메서드에 대한 인수로 사용할 수 있습니다.

최상위 수준 Express 개체에는 새 라우터 개체를 만드는 라우터() 메서드가 있습니다.

라우터 개체를 만든 후에는 응용 프로그램과 마찬가지로 미들웨어 및 HTTP 메서드 경로(예: get, put, post 등)를 추가할 수 있습니다.

 

 

 

 

 

일반적으로 route는 데이터 패킷에 대한 네트워크상의 최적의 경로를 설정하는 일입니다

URL request를 받아서 함수에 전달하는거니
여기서는 ('/', function) 라 쓰면 해당 주소를 요청하면 함수가 작동하도록 경로를 설정한거죠

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함