curriculum/challenges/english/blocks/lecture-understanding-how-http-dns-tcpip-work/69661d2fc36411aa9e25ea64.md
Let’s learn about common HTTP response codes.
HTTP response codes are three-digit numerical codes that web servers use to communicate with clients to let them know what happened with their requests.
They provide information about whether the request was handled successfully or if there was an error while handling the request.
We’ll cover some of the most common ones in this lecture.
Let’s start with success codes. These codes start with the number 2.
The code 200 OK is the most common HTTP response code. It means that the request was successful and the server returned the information requested by the client.
The code 201 Created is returned by the server when the client requests creating a resource and the process is completed successfully. For example, if a new user account is created successfully, the server returns this response code to the client.
The code 204 No Content is returned when the request has been handled successfully but the server has no content to return. This can be used for processes that delete or update a resource in a database but have no data to return.
Now let’s talk about redirection codes.
These codes are returned by the server when the resource request by the client has been moved to a different location or when the client needs to take additional steps to complete the request.
These codes start with the number 3.
The code 301 Moved Permanently is returned when the resource requested by the client has been moved permanently to another location. In this case, the server should include a URL to the new location in the response and once the client receives the response, the user should be redirected to this URL.
The code 302 Found indicates that the resource requested by the client has been temporarily moved to another location. The server should provide the new URL in the response and the client should redirect the user to this URL. However, the original URL might be available in the future since the change is temporary. That is the main difference between the response codes 301 and 302.
The code 304 Not Modified is returned by the server to tell the client that the resource requested has not been modified since the last time it was requested. The server sends this code to avoid sending data that has already been sent if the content has not changed. It’s a performance optimization technique.
Now we’ll start diving into error codes.
Errors can be caused by the client and by the server. We’ll talk about client error codes first.
Client error codes are returned when the request could not be completed because of an issue generated by the client.
These error codes start with the number 4.
The 400 Bad Request code is returned when the server could not understand the request sent by the client. This can occur when the client sends a request with incorrect syntax, with invalid parameters, or invalid data.
The 401 Unauthorized code is related to authentication. It indicates that the client has to provide certain authentication credentials to access the resource that is being requested. These credentials may include a username and a password.
The 403 Forbidden code is returned when the client is not authorized to access the requested resource. The difference between 401 and 403 is that in 403, the client doesn’t have the necessary permissions for the particular resource it’s requesting, even if it has valid authentication credentials.
The 404 Not Found code is returned when the resource could not be found on the server. Maybe it was deleted or there is a typo in the URL that prevents the server from finding the resource. The server may also be experiencing a temporary issue that results in this error code.
Next, we have server error codes. These codes are returned by the server when the request could not be processed because of an issue on the server’s end.
The 500 Internal Server Error error code indicates that there was an unexpected error on the server. This error could be caused by a wide range of issues, ranging from configuration issues to temporary issues.
The 502 Bad Gateway error code is returned when the server was trying to communicate with another server but received an invalid response from that server. There is a wide range of causes for this type of error.
The 503 Service Unavailable error code indicates that the server will not be able to handle the request temporarily, so the client should try again later. Common causes for this error include maintenance tasks and high volume of requests that the server is currently unable to handle.
HTTP response codes are essential for understanding the communication between clients and web servers. By understanding these codes, you can troubleshoot and debug your web applications.
Which HTTP response code indicates that the server successfully processed the request and returned the requested content?
404 Not Found
Think about a successful response from a web server.
500 Internal Server Error
Think about a successful response from a web server.
301 Moved Permanently
Think about a successful response from a web server.
200 OK
4
What does a 404 Not Found response code indicate?
The server could not understand the request.
Think about what it means when a resource cannot be found.
The requested resource was not found on the server.
The client is not authorized to access the resource.
Think about what it means when a resource cannot be found.
The server is temporarily unavailable.
Think about what it means when a resource cannot be found.
2
Which HTTP response code indicates a generic server-side error?
200 OK
Think about errors that occur on the server's side.
301 Moved Permanently
Think about errors that occur on the server's side.
404 Not Found
Think about errors that occur on the server's side.
500 Internal Server Error
4