API Testing – meaning of common HTTP Status Codes

Tram Ho

200 OK: This is the most successful status code and also the most commonly used status code. 400 – Bad Request: If the server returns this status code, it means that your request is malformed and cannot be processed by the server.

First of all, I would like to say hello to everyone, have a good day at work and study. In this article, I will introduce the meaning of HTTP Status Codes in API Testing.

1. HTTP Status Code

HTTP Status Code is an HTTP status code . The HTTP Status code will be returned by the server after receiving and interpreting an HTTP request from the client. Accordingly, the HTTP status code is a 3-digit code. The first digit from 1 to 5 (corresponding to 5 items to determine the type of response), 2 numbers also explain the details of the response.

To test the API, we don’t need to know all the HTTP Status codes. We just need to know what category the response falls under, and some common specific HTTP status codes.

HTTP Status Codes are classified into 5 categories :

  • 1xx (100 – 199): Information responses – The request has been accepted and processing is continuing.
  • 2xx (200 – 299): Successful responses – The request has been successfully received, understood and processed by the server.
  • 3xx (300 – 399): Redirects / Navigation – The client side needs to take additional action to complete the request.
  • 4xx (400 – 499): Client errors / Client side error – The request could not be completed or the request contains incorrect syntax. This is a client error due to an invalid request.
  • 5xx (500 – 599): Server errors / Server-side error – The server could not complete a supposedly valid request. When 5xx happens, you can only wait for the server system to finish processing.

2. Meaning of Common HTTP Status Codes

  • 200 – OK : This is the successful request status code and also the most commonly used status code. If your website returns this status code, it means that the user’s site request has been processed successfully.
  • 400 – Bad Request : If the server returns this status code, it means that your request is malformed and cannot be processed by the server. If you encounter this status code, recheck your request so the error can be corrected and try again.
  • 401 – Unauthorized : This status code will be returned if your request is not authenticated. To access some resources on the website, you need to provide login information and be pre-authenticated.
  • 403 – Forbidden : This status code is used when the server rejects your request for security reasons. This can come from the server configuration or from other security settings.
  • 404 – Not Found : This status code is returned when the server cannot find your request. If you come across this status code, the first thing you should do is double check your request path.
  • 500 – Server error : General error message about server-side problems, such as environment not working (missing library, unable to connect to database)
  • 503 – Service Unavailable : An HTTP status code used to indicate that the server cannot process your request at that time because it is down or under maintenance. This is usually a temporary message, but sometimes it can also indicate that the server is unable to process the request because of an overload or a software error.

3. HTTP Status Code illustrative examples

  • 200 OK : the request was successful and the response contains the required information. For example , the website works properly, the data returned is correct.
  • 201 Created : the request has successfully created a new request resource. For example , create a new blog post.
  • 400 Bad Request : invalid request or missing required information. Example : invalid parameter value, required parameter is missing.
  • 401 Unauthorized : the request requires user authentication before processing. For example , when the user enters the wrong password or is not logged in.
  • 403 Forbidden : request denied because the user does not have access to the request body. For example , when a user tries to access another user account.
  • 404 Not Found : The requested resource does not exist on the server. For example , when a user visits a website that does not exist.
  • 500 Internal Server Error : An error occurred on the server while processing the request. For example : database connection error, error handling error, or unspecified error.

4. Summary

In this article, I have summarized a few HTTP Status Codes. Hope it is useful knowledge for you. You can refer to other HTTP Status Codes at this link: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status

Finally, thank you to everyone who read the article!

Share the news now

Source : Viblo