WEB REQUESTS & Status Code

WEB REQUESTS & Status Code

Types of Web Request and Status Code

WEB REQUESTS

A Web Request is a communicative message that is transmitted between the client or web browsers to the servers.

TYPES OF WEB REQUESTS -

webreq.png

These are not all the Web Request but following are majorly used in the Tech Giants.

  • GET Requesting Information
    • Let's say if your on the shopping website and you are searching for the t-shirt and you get your result that's actually GET request.
    • When you are sorting, filtering and getting the request these all are GET requests because you are not putting any information on the database, you are just asking for it.
  • For all asking information we do request and thats all GET requests.

  • POST Add to database

    • It usually adds something to the database like if in case of someone is sending something to the database that gonna add then definately it's going to be Post Request.
    • Now, incase any sensitive information is travelling like passwords or something else, it is always recommended that it Web Developer use POST Request because in the POST the data don't travel like in URL or something that is much not safe.
  • So in the case whenever there is data-base involved and you want to put some information or store permanently then in that such case POST request is being used.

  • PUT

    • Edit to database
    • Whenever there is database information already present and you want to update it, In that case PUT request is being used.
    • For example if you want to change the name, age, photos etc which are already present in the database then in that case PUT request comes into the picture.
  • DELETE

    • DELETE to database
      • It is the type of the request that deletes something from the database.

User don't care about sending Web Request but as a Web Developer you need to take care all about this.

For more information on web requests you can visit this link developer.mozilla.org/en-US/docs/Web/HTTP/M..


What is HTTP Status Code ?

The Idea behind these all status code is to provide as information to browser as much possible without doing as much of work, the status code does the work for you.

  • Whenever we open any website on our Web Browser, there we get a response from the server side that we also call it a Web-Server.
  • HTTP header request is actually what we send from our web Browsers which acts as a client and the HTTP response that we get from the server as per the request.
  • Now, here we need to understand whether the HTTP header response has been successfully completed or not and this information we get from the HTTP Response.

All the Status Codes that are existing over there ?

  1. 1XX status code- Now X here refers to any numbers, all the status codes related to 1xx are informational responses.

    • You have 100 requests that refers to continue.
    • This 100 continue indicates that the client should continue the request or ignore the response if the request is already finished.

    • We have Status Code 101 that is Switching Protocols

      • This code is sent in response to an upgrade request header from the client and indicates the Protocol that the server is switching too.
    • Processing 102 next we have 102 Processing

      • This code indicates that the server has received and is processing the request but no further response is available yet.
  2. Now up we have 103 that is for the early hands

    • This status code is primarily intended to be used with a link header, letting the user agent start preloading resources while the server prepares for the response.
  3. We have Status Code 2XX that is success (OK)

    • Any code in the 200 category-section simply means that the request that you made was the good request, it was successfull, it completed what it was supposed to do.
    • So 200 is the most general success message that you can send to the people and it is something that you gonna see all the time.
    • 201 Created Status Code
      • If you are building the rest api, all of your post request to create the resources for example - create user, create Item, create shopping cart etc, when you create somethig on API you want to return 201 status code which essentially says created it is just means you created some resource and it was successfull.
      • 204 Status Code (No Content)
        • Something went well, everything worked well but you have nothing to return
        • A lot of time when you have a delete request to an api, and you want to delete user, you don't have to return anything from the API call, the API server is not going to give you information back because you just sent them an ID to delete and they deleted it so they are going to send you back a 204 and this 204 essentially says we did what you wanted us to do it and it was successful and we have nothing to return.

    A lot of times if you don't return 204 and you just return a 200, the browser or the person consuming your API might get confused because those say ok, but you gave me nothing in return

But if you return Status 204, that shows that you are telling the person using your API is we are not sending you anything but that's ok we aren't expecting to send you anything. In simple words sending you nothing is exactly what we want.


  1. 300 Status Code (Redirection)

  2. These actually are handled if you want to redirect the user so if someone goes to for an example so website and that website actually redirecting into another web page URL, you are going to get 300 status code from the very first URL that you go to which is saying hey this web page used to be here but now it's over here

  3. There are a bunch of different codes to indicate different levels of redirections but the main one is listed below.
  4. Status 304 This 304 is not actually much about redirecting the user from one URL to another, it deals with the caching information.
  5. Whenever you make a call to an API maybe you don't want to get all the results every time because they don't change that often maybe they change every couple of days but you want to query it constantly.
  6. Just in case something you want to be updated immediately , we can do this when you are calling that API you send it up a message that says this has been changed since X date since yesterday.
  7. If it has not been changed since yesterday, the server then sends back this status 304 Not Modified that indicates nothing has changed since yesterday and don't even worry about it.
  8. And in that way you don't need to download any extra information.
  9. The idea behind Status Code 304 is just a way to save bandwidth essentially instead of having to download everything everytime, it says pull from the cache that you have.

  1. Status Code 400 Client Error

  2. 400 level error is a error from the cleint side, so the person using your API sent you either bad information they aren't authorized something along the lines of what the user sent you was bad which is different than 500 level errors which actually broke on the server.

    • 400 Bad Request This one is basic 400 error this is a general error that indicates something went wrong

    • Something happened, your information was bad and I'm telling you it's bad by sending you a 400.

    • For example if you want to create a new user and you need to pass a name and an email and the client that's using the API only sent the name, they did't send you email so that is the bad request then you send them back that 400 error indicating that you didn't give me all the information I need because the name and email are required so you send a 400 error.

  3. 401(Unauthorized) and 403(Forbidden) status code
    • These are very similar to each one.
    • In case of status code 401, it is unauthorized and therefore forbidden that simply means you want to access something that requires some form of authentication, you must be logged in or you need an API key.
  4. Something that you haven't passed it or the one you passed was just incorrect the server didn't know what you meant.
  5. In case you haven't sent the API Key the server will respond with the 401 saying, I don't know who are you, you havn't given API, all you need please give the API key.
  6. But in case of Status 403 It would happen if the client sent API key but the services they are trying to access are having different permissions.
  7. Lets say they are basic user and tried to access the admin feature in the API, the server will give the error by saying I know who you are, you don't have permission to access his so I'm going to say you are forbidden from this *status code 403 , you need to have admin credentials.

401 says I have no idea who you are in other hand 403 status code says I know who you are but you cn't access so go away


  1. Status code 500
  2. Everything the user send you was correct but the server that's running the API had some kind of error maybe the database is down, some kind of exception was thrown that will be 500 level error.
  3. something bad happened that you did not expect to happen so you are saying I don't know what happened the server is broken here's a 500 error.