HTTP response status codes | REST API response codes | @ConceptandCoding
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
π 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.
π 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
π‘1xx Informational
π‘2xx Success
π‘3xx Redirection
π‘4xx Client Error
π‘5xx Server Error
π‘100 Continue
π‘200 OK
π‘201 Created
π‘400 Bad Request
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
hey guys Shan side and welcome to 10
minute series and today I will be
discussing about the response codes so
to I have picked top 10 response codes
and if you see before even we look at
the response code a
response generally contain three parts
status C header and body so the status
code is further divided into five
categories 1 XX 2 XX 3xx X 4xx
5xx the 1 XX is mean informational what
do you mean by informational is so I
would consider it as
an mid mid mid response by a server so
it is not a final
response but you are saying that server
is sending one informational return to a
client that hey yes you can proceed
further something like that so it's an
information provided by client right and
that's why the 1xx category is known as
informational so one of the is 100 which
is stand for continue so what happened
in this is right so here the
client and there is a
server so client first send a request to
the server and it say that
hey expect back and it will pass 100 now
when the server got this API so mostly
this is used in post apis now when
server get this request post request and
in the header when it say has expect 100
what server will do it will not process
the request it will first
validate okay will it server will it be
able to handle the request which is
going to be sent by client so client
also send multiple things in the header
like what should be the content
type content
length Etc so now let's say content
length is 1 MB so server validate
everything okay will I be able to handle
1 MB of data will I be able to handle
this content type or not so one server
validate everything server send a
response back with the 100 return code
100 yes you can continue and after that
client ultimately send the post request
but without expect and ultimately the
server actually process it and
ultimately it will return the Response
Code whatever the response coded so here
if you see this 100 this is nothing but
a inim return code then another category
is 2xx so 2xx is generally referred to
as a success category so here if you see
these are the four popular uh return
codes so 200 which you see mostly
during get call so whenever you do a get
call you will see that 200 okay so in
this 200 you have a status code you have
a body also remember you have a body
also means some data is actually
returned here in the
body okay 2011 created this is mostly
generally used in the post
apis 2011 created means that uh request
is successful and new records are
getting created in the DB okay so that's
why it's mostly used in the post apis
and this also has body response body
means some data has been returned to the
client 202 accepted so here what
happened is in this one considered that
some API let's say that for export
export API so now when you invoke this
API what server over will do that it
validate everything and it accepted the
request successfully but the response
has not been sent yet so it will say
that hey I accepted it I will process it
but you can check back later and the
third is 204 no content so this is
mostly frequently used during delete
so when you delete there is no content
there is no body to be returned actually
so that's why whenever we don't have any
response body to be returned or it is
empty we generally send 204 no content
and that's why it is very frequently
used with the delete when you are
deleting a particular
item then we have another category
called 3xx which is nothing but a
redirect so here what happen is when a
client is uh approaching your API now
you are redirecting the client to some
other API so this 3xx is particular
useful when you are doing a migration
from Legacy to new apis some Legacy old
API to new apis you can say that so one
of the return code is like 301 which
says that move permanently so what
happen is let's say the client hit your
API called
slash old API let's say that
now this old API is deprecated and you
want client to use the new API right so
what you do is in response you return
301 which means move permanently and in
the
header and in the header part what you
will do is you will put the
location location of new
URI or new API so what happen is client
when get this respon response code 301
it will check that okay what is the new
API which I need to use so in the header
it will look for location and whatever
the new URI we have provided it will use
that there is something called 4xx which
is a category of validation failure at
400 bad request so bad request is that
certain data is required which is not
provided by the client so it's a client
fault so client hasn't provided me the
data which I needed it so we call it as
a bed request so let's say in for uh one
API you need name without name you
cannot proceed and if that name is
coming as empty you will say that hey
it's bad request right uh name is itself
is not coming or some something is
missing which is
required then something else called 404
not found in this one what happen is
let's say and it is mostly frequently
used in like uh your
patch get 44 not found so what happen is
or even also in delete
also so now let's say that you want to
get slash 1 2 3 4 5 hey get me the user
detail of 1 2 3 4 5 but in your DB there
is no such user present with ID 1 2 3 4
5 you haven't got the data itself in
your DB so so what you will send 404 not
found and there is something called
422 422 is stand for unprocessable
entity so this is actually your business
logic everything is correct from the
client means it has passed all the 10
fields which you required let's say
right data is also present everything is
good there is
no everything is good but your business
logic currently does not support that
use case in that we say that hey we
cannot process this for example for
example uh for example let's say
that you cannot add uh particular
country user let's say that France user
currently we cannot add because uh uh
your company haven't got the licensing
so you can add different different
country user but France users you cannot
onboard now if the request
comes for you will check your business
logic hey everything is present name
country everything but now your business
logic says that hey country France hey
we cannot onboard this user so now this
is your business logic so you will send
4202 unprocessable entity and the
another category is your five access
which is server error and which is
something we should avoid this one this
is uh if this increase right means your
your component is not doing well right
so this is like 500 which is uh
equivalent to internal server error
means from client side everything is
good you got a valid request and even it
should get process it should request
should get success but because of server
error the request got
failed right maybe null pointer
exception some typ casting exception
some BB uh down error something your
server issue otherwise if if your server
doesn't have any issue this request
should be success but because of your
server we are throwing internal server
error okay guys thank you bye
5.0 / 5 (0 votes)