diff --git a/docs/expressjs/13-http-methods-and-status-codes/13-http-methods-and-status-codes.md b/docs/expressjs/13-http-methods-and-status-codes/13-http-methods-and-status-codes.md new file mode 100644 index 00000000..aa4014f8 --- /dev/null +++ b/docs/expressjs/13-http-methods-and-status-codes/13-http-methods-and-status-codes.md @@ -0,0 +1,115 @@ +--- +title: "HTTP methods and Status Codes" +description: "HTTP methods and Status Codes" +hide_table_of_contents: true +--- + +# HTTP methods and Status Codes + +## HTTP Methods + +### πŸ€”What is HTTP Methods ? + +HTTP Methods are **different ways to tell a server what action you want to perform** on a resource (data). + +### 🧐How It Work? + + + +### πŸ“‹ List of HTTP Methods + +1. GET
+2. POST
+3. PUT
+4. PATCH
+5. DELETE
+6. HEAD + + + +1. **GET** + + - **Purpose:** Retrieve data from the server (**read-only, no changes**) + - **Example:** Get a user profile + +2. **POST** + + - **Purpose:** Send data to create a new resource (**create**) + - **Example:** Submit a form to register a user + +3. **PUT** + + - **Purpose:** Replace the entire resource (**update completely**) + - **Example:** Update all details of a product + +4. **PATCH** + + - **Purpose:** Modify part of a resource (**update partially**) + - **Example:** Change only the email of a user + +5. **DELETE** + + - **Purpose:** Remove a resource + - **Example:** Delete a blog post + +6. **HEAD** + - **Purpose:** Same as GET, but only returns headers + - **Example:** Check if a file exists without downloading it + +## Status Codes + +### πŸ€” What are Status Codes? ? + +HTTP Status Codes are **3-digit numbers sent by the server** to indicate the result of your request. +Think of them like traffic signals β€” they tell you if the request was successful, redirected, failed, or something else. + +#### πŸ”΅ 1xx: Informational + +- Code
+ 100 - Continue
+ 101 - Switching Protocols + +#### 🟒2xx: Success + +- Code
+ 200 - OK
+ 201 - Created (for POST/PUT)
+ 204 - No Content (successful, no body) + +#### 🟑3xx: Redirection + +- Code
+ 301 - Moved Permanently
+ 302 - Found (Temporary Redirect)
+ 304 - Not Modified + +#### πŸ”΄4xx: Client Errors + +- Code
+ 400 - Bad Request
+ 401 - Unauthorized (login required)
+ 403 - Forbidden (access denied)
+ 404 - Not Found
+ 409 - Conflict + +#### πŸ”΄5xx: Server Errors + +- Code
+ 500 - Internal Server Error
+ 502 - Bad Gateway
+ 503 - Service Unavailable + +## πŸ“Œ Real-Time Example + +#### Creating a user: + +**Scenario:** Creating a user + +**Method:** `POST` +**Request:** `/api/users` + +Possible Responses: + +- `201 Created` β†’ User added successfully +- `400 Bad Request` β†’ Data is missing +- `409 Conflict` β†’ User already exists diff --git a/static/expressjs/13/1.png b/static/expressjs/13/1.png new file mode 100644 index 00000000..54b84dab Binary files /dev/null and b/static/expressjs/13/1.png differ diff --git a/static/expressjs/13/2.jpg b/static/expressjs/13/2.jpg new file mode 100644 index 00000000..1368ff9f Binary files /dev/null and b/static/expressjs/13/2.jpg differ