Web Server

A web server is a software application that serves web pages to users over the internet. It listens for incoming HTTP requests and responds with the appropriate content, such as HTML, CSS, JavaScript, images, or other resources. We request a http server, the default port is 80, and the server will listen on that port for incoming requests. When a request is received, the server processes it and sends back the requested content to the client.

Some basic concepts:

  • DNS
  • HTTP
  • Domain
  • IP address
  • URL
  • Web Server (e.g., Apache, Nginx, hardware server)
  • HTTP Server (e.g., FastAPI, Flask, Express, Django, software server)
  • Web Application (e.g., Facebook, Twitter, Instagram, software application)
  • Load Balancer (e.g., Nginx, HAProxy, hardware load balancer)

Restful API

POST /api/accounts Delete /api/accounts/123 GET /api/accounts/123 PUT /api/accounts/123: entierely replace the account with the new data PATCH /api/accounts/123: partially update the account with the new data, only fields provided in the request body will be updated, other fields will remain unchanged.

Design a URL

A little example of a URL design.

Get account information for specific account and date range: GET /api/accounts/1?from=2024-01-01&to=2024-01-31

Design News Feed API

  1. Design news feeds list web API format.

Get https://www.lesbaguettes.com/api/newsfeeds We should use GET and the endpoint should be /api/newsfeeds. The response should include a list of news feeds.

  1. Design API reponse format. We need to return the struture data in this API, we can use JSON format to return the data. Because we only need data from the api not the html page.
{
  "newsfeeds": [
    {
      "id": 1,
      "title": "News Feed 1",
      "content": "This is the content of news feed 1.",
      "author": "Author 1",
      "created_at": "2024-01-01T00:00:00Z"
    },
    {
      "id": 2,
      "title": "News Feed 2",
      "content": "This is the content of news feed 2.",
      "author": "Author 2",
      "created_at": "2024-01-02T00:00:00Z"
    }
  ]
}