오즈코딩스쿨 초격차캠프 백엔드 8일차

Hyemin Kim·2023년 12월 18일
0

✅ 1. JWT (JSON Web Token)

JSON Web Token (JWT)은 웹에서 정보를 안전하게 전송하기 위한 표준으로 사용되는 토큰입니다. JWT는 JSON 형식을 기반으로 하고 있으며, 서버와 클라이언트 간의 정보를 안전하게 주고받을 수 있도록 설계되었습니다.

JWT의 구조는 세 가지 부분으로 나뉘어 있습니다:

  1. Header(헤더): JWT의 타입과 사용하는 암호화 알고리즘 등의 정보를 담고 있는 부분입니다. 이 부분은 Base64로 인코딩되어 있습니다.

  2. Payload(페이로드): 토큰에 담을 정보가 포함된 부분입니다. 클레임(claim)이라고 불리는 키-값 쌍으로 이루어져 있으며, 토큰에 담길 정보들이 여기에 포함됩니다. 또한, 이 부분도 Base64로 인코딩됩니다.

  3. Signature(서명): 헤더와 페이로드의 내용을 인코딩하고, 비밀 키(secret key)를 이용하여 서명한 부분입니다. 서명을 통해 토큰이 유효하고 변경되지 않았음을 확인할 수 있습니다.

JWT는 특히 웹 애플리케이션에서 사용자 인증과 관련된 정보를 안전하게 전달하는 데에 많이 사용됩니다. 사용자가 로그인하면 서버에서 JWT를 발급하고, 클라이언트는 이를 저장해두었다가 인증이 필요한 요청을 보낼 때 헤더에 JWT를 포함시켜 서버에 전송합니다. 서버는 JWT의 서명을 확인하여 토큰이 유효한지 검증하고, 필요한 정보를 토대로 작업을 수행합니다.

- What is JWT?

JWT stands for JSON Web Token. It is a compact, URL-safe means of representing claims to be transferred between two parties. The claims in a JWT are encoded as a JSON object that is used as the payload of a JSON Web Signature (JWS) structure or as the plaintext of a JSON Web Encryption (JWE) structure, enabling the claims to be digitally signed or integrity protected with a Message Authentication Code (MAC) and/or encrypted.

In simpler terms, a JWT is a token format for securely transmitting information between parties. It is commonly used for authentication and authorization purposes in web development. JWTs consist of three parts: a header, a payload, and a signature. The header and payload are Base64-encoded JSON strings, and the signature is used to verify the integrity of the token.

JWTs are often used in scenarios where a user logs in, and the server issues a JWT to the client as a way of representing the user's identity. This token can then be sent back to the server with each subsequent request to access protected resources. The server can validate the token, extract information about the user from the payload, and make authorization decisions based on the claims within the JWT.

✅ 2. 클라우드란?

클라우드(Cloud)는 인터넷을 통해 컴퓨팅 서비스, 데이터 스토리지, 네트워킹, 소프트웨어, 분석, 인프라 등을 제공하는 서비스를 일컫습니다. 클라우드 컴퓨팅은 기업이나 개인이 자체적으로 데이터 센터를 구축하거나 유지 관리하지 않고도 필요한 컴퓨팅 리소스에 접근할 수 있게 하는 혁신적인 기술과 비즈니스 모델을 나타냅니다.

클라우드 컴퓨팅은 크게 세 가지 모델로 구분됩니다:

  1. 인프라스트럭처 서비스 (IaaS - Infrastructure as a Service):

    • 가상 서버, 스토리지, 네트워킹 등의 인프라를 제공합니다. 사용자는 이를 활용하여 자체적으로 원하는 소프트웨어, 애플리케이션, 운영체제 등을 설치하고 관리할 수 있습니다.
  2. 플랫폼 서비스 (PaaS - Platform as a Service):

    • 애플리케이션 개발 및 배포를 위한 플랫폼을 제공합니다. 사용자는 애플리케이션 개발에 집중하고 클라우드 제공자가 나머지 부분(운영체제, 런타임, 데이터베이스 등)을 관리합니다.
  3. 소프트웨어 서비스 (SaaS - Software as a Service):

    • 완제품 소프트웨어 서비스를 제공합니다. 사용자는 별도의 설치나 설정 없이 클라우드에서 제공되는 소프트웨어를 사용할 수 있습니다.

클라우드 컴퓨팅의 장점으로는 자원의 효율적인 사용, 유연한 확장성, 관리의 편의성, 초기 투자 비용의 감소 등이 있습니다. 많은 기업과 개발자들이 클라우드를 활용하여 서비스를 구축하고 운영하고 있습니다. 주요 클라우드 서비스 제공자로는 Amazon Web Services (AWS), Microsoft Azure, Google Cloud Platform (GCP), IBM Cloud 등이 있습니다.

- What is Cloud?

The term "cloud" in the context of computing generally refers to cloud computing, which is a technology that allows users to access and use computing resources (such as servers, storage, databases, networking, software, analytics, and more) over the Internet. Instead of owning and maintaining physical hardware or servers, users can leverage the resources provided by cloud service providers.

In cloud computing, these resources are delivered as services, and users can access and use them on a pay-as-you-go basis. The services are often categorized into three main models:

  1. Infrastructure as a Service (IaaS):

    • Provides virtualized computing resources over the Internet. Users can rent virtual machines, storage, and networking components.
  2. Platform as a Service (PaaS):

    • Offers a platform allowing customers to develop, run, and manage applications without dealing with the complexity of building and maintaining the underlying infrastructure.
  3. Software as a Service (SaaS):

    • Delivers software applications over the Internet on a subscription basis. Users can access the software through a web browser without needing to install or maintain it locally.

Cloud computing provides several advantages, including:

  • Scalability: Users can easily scale up or down based on their requirements.
  • Flexibility: Resources are available on-demand and can be quickly provisioned.
  • Cost-Efficiency: Users pay for the resources they consume, avoiding the need for significant upfront investments.
  • Reliability and Availability: Cloud service providers typically offer high levels of reliability and availability.

Major cloud service providers include Amazon Web Services (AWS), Microsoft Azure, Google Cloud Platform (GCP), IBM Cloud, and others.

✅ 3. 자바스크립트 엔진이 코드를 실행하는 과정

자바스크립트 엔진이 코드를 실행하는 과정은 다음과 같습니다:

  1. 토큰화(Tokenization):

    • 소스 코드를 읽고, 각각의 문자열을 의미있는 단위인 토큰으로 분해합니다. 토큰은 문법적인 의미를 가지며, 코드의 구조를 파악하는 데 사용됩니다.
  2. 구문 분석(Syntax Parsing 또는 Parsing):

    • 토큰을 가지고 문법적인 구조를 이해하고, 이를 나타내는 구문 트리(Syntax Tree)를 생성합니다. 구문 트리는 코드의 구조와 관계를 표현하며, 이후의 단계에서 이를 기반으로 코드를 실행합니다.
  3. AST 생성(Abstract Syntax Tree):

    • 구문 분석 단계에서 생성된 구문 트리는 추상적인 문법 구조를 나타내는 AST로 변환됩니다. AST는 코드의 의미를 보다 추상화된 형태로 표현하며, 이를 기반으로 실제 코드 실행이 이루어집니다.
  4. 바이트 코드 생성 또는 기계 코드 생성:

    • AST를 기반으로 실제로 실행될 수 있는 형태의 코드인 바이트 코드(Bytecode) 또는 기계 코드를 생성합니다. 이 단계는 인터프리터를 사용하는 경우에는 바이트 코드로, JIT(Just-In-Time) 컴파일러를 사용하는 경우에는 기계 코드로 변환됩니다.
  5. 실행:

    • 생성된 바이트 코드 또는 기계 코드가 실행되어 프로그램이 동작합니다. 이때 변수의 할당, 함수 호출, 조건문 처리, 반복문 실행 등이 이루어지며, 프로그램이 의도한 동작을 수행합니다.

주요한 자바스크립트 엔진에는 V8 (Google Chrome, Node.js), SpiderMonkey (Mozilla Firefox), JavaScriptCore (WebKit, Safari), Chakra (Microsoft Edge) 등이 있으며, 각 엔진은 코드 실행 최적화와 관련된 다양한 기술을 적용하여 성능을 향상시키고 있습니다.

- The process by which the JavaScript engine executes code

The process by which the JavaScript engine executes code involves several stages, and the exact steps may vary slightly between different JavaScript engines. Here is a generalized overview of the process:

  1. Lexical Analysis (Tokenization):

    • The source code is broken down into individual tokens, which are the smallest units of meaningful code. This process is called lexical analysis or tokenization.
  2. Syntax Parsing (Abstract Syntax Tree - AST Generation):

    • The tokens are used to build an Abstract Syntax Tree (AST) that represents the grammatical structure of the code. The AST is a hierarchical tree-like structure that reflects the relationships between different elements of the code.
  3. Intermediate Code Generation:

    • In some cases, an intermediate representation of the code, such as bytecode or machine code, may be generated. This step is not present in all JavaScript engines, as some engines use interpreters directly on the AST.
  4. Optimizations:

    • Many JavaScript engines include optimization steps to improve the performance of the code. This can involve various techniques, such as inlining functions, constant folding, and dead code elimination. Some engines use Just-In-Time (JIT) compilation to convert parts of the code into machine code for faster execution.
  5. Execution:

    • The optimized or intermediate code is executed by the engine. During execution, the engine handles variable assignments, function calls, conditionals, loops, and other language features. The result is the behavior defined by the JavaScript code.

It's worth noting that modern JavaScript engines employ various optimizations to enhance performance. These optimizations are designed to minimize the time it takes to execute code and make the execution more efficient. The process of executing JavaScript code is dynamic, and engines may adapt their strategies based on runtime profiling and analysis.

✅ 4. GET방식과 POST방식의 차이

GET 방식과 POST 방식은 HTTP 프로토콜을 사용하여 웹 서버와 통신할 때 사용되는 두 가지 주요한 요청 메서드입니다. 이 두 방식은 서버로 데이터를 전송하는 방법과 목적에서 차이가 있습니다.

GET 방식:

  1. 데이터 전송 방식:

    • GET 방식은 데이터를 URL의 파라미터로 전송합니다. 데이터는 URL의 끝에 쿼리 문자열(query string)의 형태로 포함되어 전송됩니다.
  2. 데이터 길이 제한:

    • GET 방식은 URL에 데이터가 노출되기 때문에 전송할 수 있는 데이터의 길이에 제한이 있습니다. 브라우저 및 웹 서버에 따라 길이 제한이 다를 수 있으며, 일반적으로 제한이 있는 경우가 많습니다.
  3. 캐싱 가능:

    • GET 요청은 캐싱될 수 있습니다. 동일한 GET 요청이 여러 번 발생할 때 브라우저는 캐시된 응답을 사용하여 서버에 재요청하지 않고 즉시 응답할 수 있습니다.
  4. 북마크 가능:

    • GET 요청은 브라우저의 주소 표시줄에 나타나므로 북마크가 가능합니다.

POST 방식:

  1. 데이터 전송 방식:

    • POST 방식은 데이터를 HTTP 요청의 본문(body)에 포함하여 전송합니다. 데이터가 URL에 노출되지 않으며, 숨겨진 형태로 전송됩니다.
  2. 데이터 길이 제한:

    • POST 방식은 일반적으로 GET 방식보다 더 많은 데이터를 전송할 수 있습니다. 대부분의 웹 서버 및 브라우저에서는 특별한 제한이 없거나 더 큰 제한을 가지고 있습니다.
  3. 캐싱 불가능:

    • POST 요청은 캐시되지 않습니다. 매번 새로운 요청이 서버로 전송되며, 응답도 캐시되지 않습니다.
  4. 북마크 불가능:

    • POST 요청은 브라우저의 주소 표시줄에 나타나지 않으므로 북마크가 불가능합니다.

선택 기준:

  • 보안:

    • POST 방식이 보안적으로 더 우수하다. GET 방식은 URL에 데이터가 노출되므로 민감한 정보를 전송할 때는 사용하지 않는 것이 좋다.
  • 데이터 길이:

    • 대량의 데이터를 전송해야 할 경우 POST 방식을 사용한다. GET 방식은 길이 제한이 있을 수 있기 때문이다.
  • 캐싱:

    • GET 방식은 캐싱이 가능하므로 데이터를 여러 번 요청해야 하는 상황에서 유리하다.
  • 북마크:

    • 사용자가 해당 요청을 북마크하고 싶을 때는 GET 방식을 사용한다.

개발 시에는 이러한 차이를 고려하여 데이터 전송 방식을 선택하게 됩니다.

- Difference between GET method and POST method

The GET and POST methods are two of the HTTP request methods used for communication between a client (usually a web browser) and a web server. Here are the key differences between the GET and POST methods:

GET Method:

  1. Data Transmission:

    • Data is transmitted in the URL's query parameters. The data is appended to the URL, visible in the browser's address bar.
  2. Data Length Limitation:

    • There is a limitation on the length of the data that can be sent with a GET request. Different browsers and servers may have different limitations.
  3. Caching:

    • GET requests can be cached by the browser. If the same GET request is made multiple times, the browser may use the cached response without re-requesting it from the server.
  4. Bookmarking:

    • GET requests can be bookmarked as the parameters are part of the URL and visible in the address bar.
  5. Security:

    • Considered less secure for sensitive data because data is exposed in the URL.

POST Method:

  1. Data Transmission:

    • Data is transmitted in the body of the HTTP request. The data is not visible in the URL.
  2. Data Length Limitation:

    • POST requests generally allow larger amounts of data to be sent. The limitation is typically imposed by the server or the client.
  3. Caching:

    • POST requests are not cached by default. Each request is treated as a unique one, and the response is not stored for reuse.
  4. Bookmarking:

    • POST requests cannot be bookmarked as the data is not part of the URL and not visible in the address bar.
  5. Security:

    • Considered more secure, especially for sensitive data, as the data is not exposed in the URL. However, it doesn't inherently make the data encrypted; additional security measures (like HTTPS) may be needed.

Choosing Between GET and POST:

  • Use GET when:

    • The request is idempotent (repeated identical requests have the same effect as a single request).
    • The data to be sent is small and does not contain sensitive information.
    • The request is safe and does not have side effects on the server.
  • Use POST when:

    • The request has side effects on the server, such as modifying data or making a purchase.
    • The data to be sent is large.
    • The request contains sensitive information.

In summary, the choice between GET and POST depends on the nature of the request, the type of data being transmitted, and the desired level of security and visibility.

profile
Full Stack Web Developer

0개의 댓글