HTTP response status codes | REST API response codes | @ConceptandCoding

Shrayansh Jain
10 Sept 202409:48

Summary

TLDRIn this 10-minute series episode, the host delves into HTTP response codes, highlighting the top 10. The codes are categorized into five groups: 1xx informational, indicating the server's readiness to proceed; 2xx success, with 200 for GET requests, 201 for successful POST requests creating new records, 202 for accepted requests pending processing, and 204 for DELETE operations with no content to return; 3xx redirects, like 301 for permanent URL changes; 4xx client errors, such as 400 for bad requests due to missing data and 404 for non-existent resources; and 5xx server errors, like 500 for internal server issues. The discussion provides clarity on how these codes are used in web communications.

Takeaways

  • 📝 Response codes are divided into five categories: 1xx (Informational), 2xx (Success), 3xx (Redirection), 4xx (Client Error), and 5xx (Server Error).
  • 🔄 1xx codes are informational responses, indicating that the server is ready to communicate with the client but has not yet completed the request.
  • ✅ 100 (Continue) status code is used when a server checks the request's headers and decides it can handle the request before the client sends the body.
  • 🎯 2xx codes indicate that the client's request was successfully received, understood, and accepted by the server.
  • 👍 200 (OK) is the standard response for successful HTTP requests, typically used with GET requests, and implies that the response body contains the requested data.
  • 🆕 201 (Created) is used with POST requests to indicate that the request has been fulfilled and has resulted in the creation of a new resource.
  • đŸ—‚ïž 202 (Accepted) means that the request has been accepted for processing, but the processing is not complete, and the client can check back later for the result.
  • ❌ 204 (No Content) is used when a request is successfully processed, but there is no content to return in the response body, such as after a DELETE operation.
  • 🔄 3xx codes are for redirection, where the client must take additional action to complete the request, such as moving to a new URI.
  • 🔄 301 (Moved Permanently) is used to redirect clients to a new URI when an API endpoint has been permanently changed or deprecated.
  • đŸš« 4xx codes represent client errors, indicating that the client's request contains bad syntax or cannot be fulfilled.
  • 🚹 400 (Bad Request) is sent when the server cannot process the request due to invalid syntax or missing required data.
  • 🔍 404 (Not Found) indicates that the requested resource is not available on the server, and the client should not retry the request.
  • 🛑 422 (Unprocessable Entity) is used when the server understands the content type of the request entity and the syntax of the request is correct, but the request was unable to be followed due to semantic errors.
  • ⚠ 5xx codes are server errors, indicating that the server has failed to fulfill an apparently valid request.
  • 💡 500 (Internal Server Error) is a generic error message, given when an unexpected condition was encountered and no more specific message is suitable.

Q & A

  • What are the three parts that generally make up a response?

    -A response generally contains three parts: status code, header, and body.

  • How many categories are status codes divided into and what are they?

    -Status codes are divided into five categories: 1xx (Informational), 2xx (Success), 3xx (Redirection), 4xx (Client Error), and 5xx (Server Error).

  • What does the 1xx category of status codes indicate?

    -The 1xx category of status codes is known as informational, indicating that the server is sending an interim response to the client, signaling that the client can proceed further.

  • What is the meaning of the 100 status code?

    -The 100 status code stands for 'Continue' and is used when a server has received a request with an 'Expect: 100-continue' header and the server is ready to accept the request.

  • Which status code is commonly seen during GET requests and what does it represent?

    -The 200 status code is commonly seen during GET requests and represents 'OK', indicating that the request has succeeded and the response body contains the requested data.

  • What does the 201 status code signify and in which type of APIs is it typically used?

    -The 201 status code signifies that the request has been fulfilled and results in a new resource being created, typically used in POST APIs.

  • What is the purpose of the 202 status code and in what scenario is it commonly used?

    -The 202 status code indicates that the request has been accepted for processing but the processing has not been completed, commonly used in scenarios like export APIs where the server has accepted the request but the response is not yet available.

  • Why is the 204 status code often used with DELETE requests?

    -The 204 status code is used with DELETE requests because it indicates 'No Content', meaning that the server successfully processed the request, but is not returning any content.

  • What does the 3xx category of status codes represent and how is it typically used?

    -The 3xx category of status codes represents redirection, indicating that further action needs to be taken by the client to fulfill the request, typically used when migrating from old APIs to new ones.

  • What is the significance of the 301 status code and how does it affect the client?

    -The 301 status code signifies 'Moved Permanently', instructing the client to redirect to a new URI provided in the header, typically used when an API is deprecated and clients need to use a new API endpoint.

  • What does the 4xx category of status codes indicate and what is an example of a 4xx status code?

    -The 4xx category of status codes indicates client errors, such as 400 Bad Request, which signifies that the request cannot be processed due to incorrect syntax or missing required data.

  • What is the 422 status code and under what circumstances is it used?

    -The 422 status code stands for 'Unprocessable Entity' and is used when the server understands the content type of the request entity and the syntax of the request entity is correct, but it was unable to process the contained instructions.

  • What does the 5xx category of status codes represent and what is an example of a 5xx status code?

    -The 5xx category of status codes represents server errors, such as 500 Internal Server Error, indicating that the server encountered an unexpected condition that prevented it from fulfilling the request.

Outlines

00:00

🌐 Understanding HTTP Response Codes

The video segment discusses the structure of HTTP responses, which consist of a status line, header, and body. It delves into the categorization of status codes: 1xx (informational), 2xx (success), 3xx (redirection), 4xx (client errors), and 5xx (server errors). The 1xx category, exemplified by the 100 'Continue' status, indicates that the server has received the initial part of a request and is ready for the client to continue. The 2xx category includes the 200 'OK' for successful GET requests, 201 'Created' for POST requests resulting in new database records, 202 'Accepted' for accepted but not yet processed requests, and 204 'No Content' for actions like DELETE that don't return content. The segment also touches on 3xx codes, which are used for redirection, and sets the stage for discussing 4xx and 5xx categories in subsequent parts.

05:02

🔄 Redirection and Client/Server Error Codes

This part of the video script focuses on 3xx redirection codes, such as 301 'Moved Permanently', which is used during API migrations to direct clients from old to new endpoints. It also covers 4xx client error codes, including 400 'Bad Request' for missing required data, 404 'Not Found' for non-existent resources, and 422 'Unprocessable Entity' for requests that meet syntactical standards but fail against business logic. The script concludes with a mention of 5xx server error codes, like 500 'Internal Server Error', which should be avoided and indicate issues on the server side, such as null pointer exceptions or database downtime, despite valid client requests.

Mindmap

Keywords

💡Response Code

Response codes are numerical codes returned by a server to indicate the result of a client's request. They are categorized into different classes, such as informational, success, redirection, client errors, and server errors. In the video, response codes are central to the discussion as they help in understanding how servers communicate the outcome of various requests.

💡1xx Informational

The 1xx series of response codes, known as informational, indicates that the server has received the request and is continuing the process. An example is the 100 Continue response, where the server indicates that it has validated the initial request headers and the client can continue sending the request body. This code serves as a preliminary confirmation before the server processes the full request.

💡2xx Success

The 2xx series represents successful responses where the request was received, understood, and accepted by the server. Common codes include 200 OK, used primarily for GET requests indicating that the request was successful, and 201 Created, used in POST requests when new records are created. These codes affirm that the server has effectively handled the client’s request.

💡3xx Redirection

3xx codes are used to redirect the client to a different resource or endpoint. An example is 301 Moved Permanently, which informs the client that the resource has been permanently relocated to a new URL. Redirection codes are particularly useful when APIs are updated or restructured, guiding clients to the appropriate endpoints without errors.

💡4xx Client Error

The 4xx codes indicate that there was an error with the client's request. Common examples include 400 Bad Request, which signals that the server could not process the request due to client-side issues like missing data, and 404 Not Found, used when a requested resource is not found on the server. These codes help identify and correct issues on the client side.

💡5xx Server Error

5xx response codes indicate server-side errors where the server failed to fulfill a valid request. The 500 Internal Server Error is a common example, indicating that the server encountered an unexpected condition. These errors suggest that while the client’s request was valid, the server encountered problems, which can be due to software bugs, server overload, or other issues.

💡100 Continue

The 100 Continue response code is part of the 1xx informational class. It indicates that the server has received the request headers and the client should proceed with sending the request body. This code helps to ensure that the server is prepared to handle the request before the client sends large amounts of data, optimizing communication efficiency.

💡200 OK

The 200 OK status code is a standard success response that indicates the request has succeeded. It is most commonly seen with GET requests and includes a response body with data requested by the client. The code assures the client that the operation was successful, and the requested resource is returned in the response.

💡201 Created

The 201 Created code is used when a request has resulted in the creation of a new resource, typically seen with POST requests. The response includes a body that often contains information about the newly created resource. It confirms that the server has successfully processed the request, and a new resource is now available.

💡400 Bad Request

400 Bad Request indicates that the server could not understand the request due to invalid syntax, missing required data, or incorrect formatting from the client. This error highlights issues with the client’s request, prompting corrections before resubmission. For example, if a required field like 'name' is missing, the server will return a 400 code.

Highlights

A response generally contains three parts: status code, header, and body.

Status codes are divided into five categories: 1xx, 2xx, 3xx, 4xx, 5xx.

1xx codes are informational, indicating the server is ready to proceed with the client's request.

100 status code means 'Continue', used when the server has received the initial part of a request and is ready to receive more.

2xx codes represent success, indicating the client's request was successfully received, understood, and accepted.

200 status code is 'OK', commonly seen during GET calls, meaning the request has succeeded.

201 status code stands for 'Created', used in POST APIs when a new resource is created.

202 status code is 'Accepted', indicating the request has been accepted for processing but the processing has not been completed.

204 status code is 'No Content', used when there is no additional content to send in the response, often with DELETE requests.

3xx codes are for redirection, where the client is redirected to a different resource.

301 status code means 'Moved Permanently', used when a resource has been permanently moved to a new URI.

4xx codes indicate client errors, such as 400 'Bad Request' when the server cannot process the request due to invalid syntax.

404 status code is 'Not Found', used when a requested resource is not available on the server.

422 status code stands for 'Unprocessable Entity', indicating that the server understands the content type of the request entity and the syntax of the request entity is correct, but it was unable to process the contained instructions.

5xx codes are server errors, such as 500 'Internal Server Error', which means the server has encountered a situation it doesn't know how to handle.

It's important to avoid 5xx errors as they indicate issues with the server's functionality.

Transcripts

play00:00

hey guys Shan side and welcome to 10

play00:03

minute series and today I will be

play00:04

discussing about the response codes so

play00:07

to I have picked top 10 response codes

play00:10

and if you see before even we look at

play00:12

the response code a

play00:15

response generally contain three parts

play00:18

status C header and body so the status

play00:23

code is further divided into five

play00:26

categories 1 XX 2 XX 3xx X 4xx

play00:31

5xx the 1 XX is mean informational what

play00:35

do you mean by informational is so I

play00:38

would consider it as

play00:40

an mid mid mid response by a server so

play00:44

it is not a final

play00:46

response but you are saying that server

play00:49

is sending one informational return to a

play00:53

client that hey yes you can proceed

play00:56

further something like that so it's an

play00:58

information provided by client right and

play01:03

that's why the 1xx category is known as

play01:06

informational so one of the is 100 which

play01:10

is stand for continue so what happened

play01:13

in this is right so here the

play01:16

client and there is a

play01:20

server so client first send a request to

play01:24

the server and it say that

play01:28

hey expect back and it will pass 100 now

play01:32

when the server got this API so mostly

play01:34

this is used in post apis now when

play01:38

server get this request post request and

play01:42

in the header when it say has expect 100

play01:45

what server will do it will not process

play01:48

the request it will first

play01:50

validate okay will it server will it be

play01:54

able to handle the request which is

play01:57

going to be sent by client so client

play02:00

also send multiple things in the header

play02:02

like what should be the content

play02:05

type content

play02:08

length Etc so now let's say content

play02:11

length is 1 MB so server validate

play02:14

everything okay will I be able to handle

play02:17

1 MB of data will I be able to handle

play02:19

this content type or not so one server

play02:23

validate everything server send a

play02:25

response back with the 100 return code

play02:29

100 yes you can continue and after that

play02:33

client ultimately send the post request

play02:38

but without expect and ultimately the

play02:40

server actually process it and

play02:43

ultimately it will return the Response

play02:45

Code whatever the response coded so here

play02:47

if you see this 100 this is nothing but

play02:50

a inim return code then another category

play02:54

is 2xx so 2xx is generally referred to

play02:57

as a success category so here if you see

play02:59

these are the four popular uh return

play03:02

codes so 200 which you see mostly

play03:06

during get call so whenever you do a get

play03:10

call you will see that 200 okay so in

play03:13

this 200 you have a status code you have

play03:17

a body also remember you have a body

play03:20

also means some data is actually

play03:23

returned here in the

play03:24

body okay 2011 created this is mostly

play03:28

generally used in the post

play03:31

apis 2011 created means that uh request

play03:36

is successful and new records are

play03:38

getting created in the DB okay so that's

play03:41

why it's mostly used in the post apis

play03:44

and this also has body response body

play03:47

means some data has been returned to the

play03:50

client 202 accepted so here what

play03:53

happened is in this one considered that

play03:58

some API let's say that for export

play04:01

export API so now when you invoke this

play04:04

API what server over will do that it

play04:08

validate everything and it accepted the

play04:10

request successfully but the response

play04:14

has not been sent yet so it will say

play04:16

that hey I accepted it I will process it

play04:20

but you can check back later and the

play04:23

third is 204 no content so this is

play04:26

mostly frequently used during delete

play04:30

so when you delete there is no content

play04:32

there is no body to be returned actually

play04:35

so that's why whenever we don't have any

play04:38

response body to be returned or it is

play04:41

empty we generally send 204 no content

play04:45

and that's why it is very frequently

play04:47

used with the delete when you are

play04:49

deleting a particular

play04:51

item then we have another category

play04:53

called 3xx which is nothing but a

play04:55

redirect so here what happen is when a

play04:58

client is uh approaching your API now

play05:02

you are redirecting the client to some

play05:04

other API so this 3xx is particular

play05:09

useful when you are doing a migration

play05:11

from Legacy to new apis some Legacy old

play05:15

API to new apis you can say that so one

play05:17

of the return code is like 301 which

play05:20

says that move permanently so what

play05:22

happen is let's say the client hit your

play05:24

API called

play05:26

slash old API let's say that

play05:30

now this old API is deprecated and you

play05:33

want client to use the new API right so

play05:37

what you do is in response you return

play05:41

301 which means move permanently and in

play05:44

the

play05:46

header and in the header part what you

play05:49

will do is you will put the

play05:51

location location of new

play05:54

URI or new API so what happen is client

play05:58

when get this respon response code 301

play06:01

it will check that okay what is the new

play06:03

API which I need to use so in the header

play06:05

it will look for location and whatever

play06:08

the new URI we have provided it will use

play06:10

that there is something called 4xx which

play06:13

is a category of validation failure at

play06:16

400 bad request so bad request is that

play06:20

certain data is required which is not

play06:24

provided by the client so it's a client

play06:27

fault so client hasn't provided me the

play06:30

data which I needed it so we call it as

play06:34

a bed request so let's say in for uh one

play06:37

API you need name without name you

play06:41

cannot proceed and if that name is

play06:43

coming as empty you will say that hey

play06:45

it's bad request right uh name is itself

play06:48

is not coming or some something is

play06:50

missing which is

play06:52

required then something else called 404

play06:54

not found in this one what happen is

play06:57

let's say and it is mostly frequently

play06:59

used in like uh your

play07:03

patch get 44 not found so what happen is

play07:08

or even also in delete

play07:10

also so now let's say that you want to

play07:14

get slash 1 2 3 4 5 hey get me the user

play07:19

detail of 1 2 3 4 5 but in your DB there

play07:22

is no such user present with ID 1 2 3 4

play07:25

5 you haven't got the data itself in

play07:28

your DB so so what you will send 404 not

play07:31

found and there is something called

play07:34

422 422 is stand for unprocessable

play07:37

entity so this is actually your business

play07:40

logic everything is correct from the

play07:42

client means it has passed all the 10

play07:46

fields which you required let's say

play07:49

right data is also present everything is

play07:51

good there is

play07:53

no everything is good but your business

play07:57

logic currently does not support that

play08:00

use case in that we say that hey we

play08:03

cannot process this for example for

play08:06

example uh for example let's say

play08:10

that you cannot add uh particular

play08:14

country user let's say that France user

play08:17

currently we cannot add because uh uh

play08:20

your company haven't got the licensing

play08:23

so you can add different different

play08:25

country user but France users you cannot

play08:27

onboard now if the request

play08:30

comes for you will check your business

play08:32

logic hey everything is present name

play08:35

country everything but now your business

play08:37

logic says that hey country France hey

play08:40

we cannot onboard this user so now this

play08:42

is your business logic so you will send

play08:44

4202 unprocessable entity and the

play08:47

another category is your five access

play08:49

which is server error and which is

play08:51

something we should avoid this one this

play08:54

is uh if this increase right means your

play08:59

your component is not doing well right

play09:02

so this is like 500 which is uh

play09:06

equivalent to internal server error

play09:08

means from client side everything is

play09:10

good you got a valid request and even it

play09:15

should get process it should request

play09:17

should get success but because of server

play09:20

error the request got

play09:23

failed right maybe null pointer

play09:25

exception some typ casting exception

play09:28

some BB uh down error something your

play09:33

server issue otherwise if if your server

play09:36

doesn't have any issue this request

play09:38

should be success but because of your

play09:42

server we are throwing internal server

play09:44

error okay guys thank you bye

Rate This
★
★
★
★
★

5.0 / 5 (0 votes)

Étiquettes Connexes
HTTP CodesWeb DevelopmentStatus CodesAPI DesignClient-ServerError HandlingSuccess CodesRedirect CodesInformational CodesServer Errors
Besoin d'un résumé en anglais ?