Cookie Consent by Free Privacy Policy Generator 📌 HTTP response status codes which Beginners should know at first.


✅ HTTP response status codes which Beginners should know at first.


💡 Newskategorie: Programmierung
🔗 Quelle: dev.to

Table of contents

  1. At the beginning
  2. What is HTTP response status codes?
  3. Which HTTP response status codes do beginners should know at first?
    • 200 OK
    • 201 Created
    • 400 Bad Request
    • 401 Unauthorized
    • 403 Forbidden
    • 404 Not Found
    • 500 Internal Server Error
  4. Conclusion

At the beginning

When I first started learning web development, I was overwhelmed by lots of HTTP status codes - it seemed impossible for to memorize them all. However, as I continued developing more applications, I realized that there are only a couple of status codes that beginners really need to know at first.
This article would be the first step in learning this for beginners.

What is HTTP response status codes?

HTTP response status codes are 3-digit numbers that are part of the HTTP protocol which refers to the rules and conventions for exchanging information on the web.
They are returned by web servers to indicate the status of a client's request. The status codes are grouped into the following 5 categories.

  • 1xx Informational
  • 2xx Success
  • 3xx Redirection
  • 4xx Client Error
  • 5xx Server Error

1xx Informational

This indicates that the request was received and is being processed(100 Continue, 102 Processing).

2xx Success

This indicates that the request was received, understood, and accepted successfully(200 OK, 201 Created, 204 No Content).

3xx Redirection

This indicates that further action needs to be taken by the client in order to complete the request(301 Moved Permanently, 302 Found, 304 Not Modified).

4xx Client Error

This indicates that there was a problem with the request from the client.(400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found).

5xx Server Error

This indicates that there was a problem on the server side in fulfilling the request(500 Internal Server Error, 501 Not Implemented, 503 Service Unavailable).

Which HTTP response status codes do beginners should know at first?

200 OK

This indicates that the request was successful. It's the most common success status code.

// When you can sign-in successfully
return res.status(200).json({ message: "Sign In out successfully" });

// When you can logout successfully
return res.status(200).json({ message: "Logout successfully" });

// When a client sends a GET request to retrieve a list of users
app.get('/users', (req, res) => {
  const users = [/* fetch users from database */];
  res.status(200).json(users);
});

201 Created

This is returned whenever a new resource is created on the server, for example, after a successful POST request to create a new record.

// When a client sends a POST request to create a new user
app.post('/users', (req, res) => {
  const newUser = req.body;
  // save newUser to database
  res.status(201).json(newUser);
});

400 Bad Request

This indicates that the request wasn't formed correctly or invalid. It's a client-side error.

const { name, email } = req.body;

// Check if required fields are present
if (!name || !email) {
  return res.status(400).json({ error: 'Name and email are required' });
}

401 Unauthorized

This indicates that the client has not been authenticated or has provided invalid credentials.

// When you fail the process of user authentication
return res.status(401).send({ message: "Authentication failed" });

// When the JWT token is missing from the request and respond
const token = req.cookies.token;
if (!token) return res.status(401).json({ message: "Not Authenticated!" });

403 Forbidden

This indicates that the client has provided valid authentication credentials, but it does not have permission or authorization to access the requested resource.

// When a non-admin user attempts to access some actions
if (user.isAdmin !== 'admin') {
  return res.status(403).json({ error: 'Forbidden: Insufficient permissions' });
}

404 Not Found

This indicates that the requested resource does not exist on the server. It's still considered a client-side error, even though it may seem like it's related to the server. The reason for this is that when the client sends a request for a resource, it's the client's responsibility to request a valid resource that exists on the server.

// When user can't be found
const user = getUserById(userId);
if (!user) {
  return res.status(404).json({ error: "User not found" });
}

// When comment can't be found
const comment = getCommentById(commentId);
if (!comment) {
  return res.status(404).json({ error: "Comment not found" });

500 Internal Server Error

This is a generic server-side error code, indicating that something went wrong on the server, but the issue is unknown.

return res.status(500).json({ error: "Internal server error" });

Conclusion

It's really important for us to understand which HTTP status codes should be used when we create web applications.
Other articles are informative, so I summarize them in this article.
If you are interested in learning them, you can search more deeply.

...

✅ HTTP response status codes which Beginners should know at first.


📈 67.93 Punkte

✅ Status Codes Explained (FAQ). A List Of Every Vital HTTP Response Status Code And What They Mean.


📈 40.02 Punkte

✅ Everything You Need to Know About HTTP Response Status Codes


📈 37.18 Punkte

✅ Essential HTTP Status Codes Every Web Developer Should Know


📈 35.29 Punkte

✅ Introducing More Python for Beginners | More Python for Beginners [1 of 20] | More Python for Beginners


📈 31.51 Punkte

✅ What React beginners should know about React 19 first.


📈 28.98 Punkte

✅ Do You Know All 63 HTTP Status Codes?


📈 28.91 Punkte

✅ A story about HTTP status codes and why you should read documentation


📈 28.75 Punkte

✅ Sophos Incident Response achieves NCSC Certified Incident Response (CIR) Level 2 status


📈 25.91 Punkte

✅ [Officially switching to Linux] What Are First Things I Should Know And Steps I Should Take ?


📈 24.85 Punkte

✅ Simple and Important Linux Commands Beginners Should Know - Geekynoob


📈 23.41 Punkte

✅ How to use Adobe Lightroom: Everything beginners should know


📈 23.41 Punkte

✅ TypeScript for Beginners: What You Should Know


📈 23.41 Punkte

✅ Top 5 Python Tricks and Coding Hacks That Beginners Should Know


📈 23.41 Punkte

✅ JavaScript Strings and String Methods as a Beginners you should know


📈 23.41 Punkte

✅ HTTP Status Code and HTTP Header in Nest.js Response


📈 22.61 Punkte

✅ I made statcode. It's like 'man' pages, but for HTTP status codes


📈 22.38 Punkte

✅ HTTP-Status-Codes: Überblick & Erklärung der wichtigsten Meldungen


📈 22.38 Punkte

✅ Russian hacker group use HTTP status codes to control malware implants


📈 22.38 Punkte

✅ Russian hacker group using HTTP status codes to control malware implants


📈 22.38 Punkte

✅ HTTP Status Codes Command This Malware How to Control Hacked Systems


📈 22.38 Punkte

✅ Russian APT Turla’s COMpfun malware uses HTTP status codes to receive commands


📈 22.38 Punkte

✅ HTTP Status Codes


📈 22.38 Punkte

✅ Leverage the richness of HTTP status codes


📈 22.38 Punkte

✅ Leverage the Richness of HTTP Status Codes


📈 22.38 Punkte

✅ Understanding the most important HTTP status codes


📈 22.38 Punkte

✅ HTTP Status Codes: A Guide for Developers


📈 22.38 Punkte

✅ The HTTP Status Codes CheatSheet [SAVE IT!] 📜✨


📈 22.38 Punkte

✅ Understanding HTTP Status Codes


📈 22.38 Punkte

✅ Handling HTTP Status Codes in a REST API (200 OK vs. 201 Created)


📈 22.38 Punkte

✅ Understanding the Basics of HTTP Status Codes


📈 22.38 Punkte











matomo

Datei nicht gefunden!