Guide On HTTP Status Codes

Guide On HTTP Status Codes

Whenever the client (browser) sends a REST (GET, POST…) request to the server, the server responds back, generally with a JSON response that includes some kind of status code. We will learn about these status codes, but they reflect the state of the response the server sends back. So, what is it, and how does it work?

What is HTTP Status Code ?

HTTP response status codes show if a specific HTTP request was completed successfully or not. The responses are divided into five groups.

Common HTTP Status Codes Every Developer Should Know When Building REST Endpoints

1xx: Informational

  • 100 Continue
    The server has received the request headers and is waiting for the rest of the request. It’s a signal to proceed.

    Its like You call a friend and ask, “Should I tell you the details now?” They respond, “Go ahead, I’m listening.”
    The server is saying, “I’ve got the initial request, you can send more information.”

2xx: Success

  • 200 OK
    Everything went smoothly. The server successfully processed the request, and the response contains the requested data.

    This code is like when you ask a friend for a pen and he hands you immediately

  • 201 Created
    A new resource has been successfully created. For example, after creating a new user account, the server might return this.

    You ask a friend to bake a cake, and they say, “Done! Here’s the cake you wanted.”

3xx: Redirection

  • 301 Moved Permanently
    The requested resource has been permanently moved to a new URL. Browsers will automatically redirect to the new location.

    You ask for your friend at their old house, but someone tells you, “They’ve moved to a new address permanently.

  • 302 Found
    Temporarily redirects the user to another URL, but the original URL should still be used for future requests.

    You go to a restaurant for pizza, but they say, “Today, we’re serving it at our other branch just for today.

4xx: Client Errors

  • 400 Bad Request
    The server couldn’t understand the request due to invalid syntax. Double-check your input or request format.

    You try to book a movie ticket but provide an invalid date like February 30th. The system says, “I don’t understand this

  • 401 Unauthorized
    Authentication is required to access the resource. For example, you might need to log in before viewing a page.

    You try to enter a club without a valid ID, and the bouncer says, “No entry without proof of identity.

  • 403 Forbidden
    The server understood the request but refuses to fulfill it. This often occurs when you lack necessary permissions.

    When you are a “green flag” but still she rejects you

  • 404 Not Found
    The server couldn’t find the requested resource. It might be due to a broken link or an incorrect URL.

    You ask for your favorite book at a library, but the librarian says, “Sorry, we don’t have that here.

5xx: Server Errors

  • 500 Internal Server Error
    The server encountered an error it couldn’t handle. It’s usually an issue on the server side.

    You’re trying to fix a car, but something inside breaks, and you can’t continue

  • 503 Service Unavailable
    The server is temporarily unable to handle the request. This might be due to maintenance or high traffic.

    When you call her , but her phone says, “I’m busy right now, try again later.

To learn about more status code kindly refer this site : All status codes

Conclusion

That’s its! Knowing your HTTP status codes is a game-changer when building REST endpoints. They help you understand what’s going wrong and how to fix it. Whether it’s a simple success (200 OK) or a server meltdown (500 Error), these codes give you the clues you need to keep things running smoothly. Keep them in mind next time you're coding!

If you got something valuable from it do give it a like ❤ and share your thought on the comments

Connect with Me 👇

Github

LinkedIn