Câu hỏi phỏng vấn API Design
Câu hỏi

What are the core components of a HTTP Request?

Câu trả lời

The core components of an HTTP request are essential elements that define the structure and functionality of the request sent from a client to a server. These components include:

  1. Request Line:

    • HTTP Method: Specifies the action to be performed. Common methods include GET, POST, PUT, DELETE, PATCH, and OPTIONS.
    • Request Target: The URL or the path of the resource being requested.
    • HTTP Version: Indicates the version of the HTTP protocol being used, such as HTTP/1.1 or HTTP/2.

    Example:

    GET /index.html HTTP/1.1
  2. Headers:

    • Headers provide additional information about the request. They are key-value pairs separated by a colon and are case-insensitive. Common headers include Host, User-Agent, Accept, Content-Type, and Authorization.
    • Headers can be categorized into general headers, request headers, response headers, and entity headers.

    Example:

    Host: www.example.com
    User-Agent: Mozilla/5.0
    Accept: text/html
  3. Blank Line:

    • A blank line separates the headers from the body. It indicates the end of the header section.
  4. Body (Optional):

    • The body contains the data being sent to the server. It is used with methods like POST, PUT, and PATCH. The body can be in various formats such as JSON, XML, form data, or binary data.
    • The presence and format of the body are often indicated by headers like Content-Type and Content-Length.

    Example:

    {
      "username": "example",
      "password": "password123"
    }

Example of a Complete HTTP Request

POST /login HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0
Content-Type: application/json
Content-Length: 48

{
  "username": "example...
junior

junior

Gợi ý câu hỏi phỏng vấn

middle

Mention what is the difference between PUT and POST?

senior

Explain element?

expert

Name some best practices for better RESTful API design

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào