Tuesday, 16 April 2024

API Status Codes with examples for QA-Testers

 



🔺 LinkedIn:https://www.linkedin.com/in/sidharth-shukla-77b53145/
🔺 Telegram Group: https://t.me/+FTf_NPb--GQ2ODhl


🏮In API testing, it's not sufficient to simply memorize status codes. We also need to have a grasp of testing client-side errors. Let's explore how we can effectively verify various status codes from the 4xx series.


Here are some real-time examples of how you may encounter different HTTP status code:



*********
🔴 400 Bad Request
*********

Suppose you are working with an e-commerce API, and you attempt to create a new order without providing the required fields, suppose we need to send three fields in request product, customer, quantity but you only send product field.

👉 Request
POST /api/orders
Content Type: application/json
{ "product": "12345" }

👉 Response
400 Bad Request
Content-Type: application/json
{ "error": "Missing required fields: 'customer', 'quantity'" }



******
🔴 401 Unauthorized
******

When interacting with an authentication API, if you provide incorrect or missing credentials, you may receive a 401 status code:

👉 Request
POST /api/auth/login
Content-Type: application/json {"username": "john", "password": "incorrectpassword" }

👉 Response
401 Unauthorized
Content-Type: application/json
{ "error": "Invalid credentials" }



*****
🔴 403 Forbidden
*****


Let's say you are accessing an API that requires specific user roles or permissions to perform certain actions.

If you attempt to access a restricted resource without the necessary permissions fo example in below scenario DELETE method can only be done by Admin but you are trying to perform delete action with normal user, you’ll receive a 403 status code.

👉 Request
DELETE /api/users/123
Authorization: Bearer <token>

👉 Response
403 Forbidden
Content-Type: application/json
{ "error": "Insufficient permissions to delete user" }





👉 Try the Complete Interview Q&A Package to crack interviews for Automation Testing and SDET: https://lnkd.in/gJrBGExe






****

🔴 404 Not Found

****

When accessing a resource that doesn't exist, you may receive a 404 status code.
if you query an API for a user that doesn't exist, that means userid 999 not present in DB

👉 Request:
GET /api/users/999

👉 Response:
404 Not Found
Content-Type: application/json
{ "error": "User not found" }



****
🔴 405 Method Not Allowed
****

Suppose you are interacting with an API that only allows specific HTTP methods for a particular endpoint. If you attempt to use an unsupported method, you will receive a 405 status code,

TIPS: always use OPTIONS method to cross check what all methods are allowed

👉 Request:
PUT /api/customers/123
Content-Type: application/json
{ "name": "John Doe", "email": "john.doe@exa.com" }

👉 Response:
405 Method Not Allowed
Content-Type: application/json
{ "error": "PUT method is not allowed for this endpoint" }



***
E2E API Sessions with Postman, RestAssured, Design Patterns, Architectures, GIT, Jenkins, Framework Design from Scratch: https://lnkd.in/g9r99y8k
***

🤝For SDET or Automation Testing trainings along with career guidance, mock interviews, design patterns, Generative AI : https://lnkd.in/giCxnJJ7

***


🚀 End-to-End Automation & SDET Training:

Boost your testing career with specialized Automation Testing & SDET workshops designed for product companies! Explore API, UI, Mobile, Jenkins, GIT, Docker, and the exciting world of Generative AI. Dive into a unique learning journey featuring personalized 1:1 guidance, interactive mock sessions, and collaborative pair programming, all guided by expert Sidharth Shukla . 🌟 Check out the demo now! Demo Session

Enrol Here → https://topmate.io/sidharth_shukla/110008

+++++++

#testing #automation #qa #testautomation #career #softwaretesting #qualityassurance #qaautomation #software #testingtips #assert #testng #sdet #technology #sidpost

 SDET Interview Question and Answers

TestNG Interview questions and answers

Jenkins Interview Questions and Answers

Appium Interview Questions and Answers

Selenium Interview Questions and answers

Java Coding Interview Questions and Answers

GIT Interview Questions and Answers

No comments:

Post a Comment

All Time Popular Posts

Most Featured Post

Introduction to Web Testing with Playwright

  Introduction to Web Testing with Playwright 📌  Telegram Group:  https://t.me/+FTf_NPb--GQ2ODhl 📌  YouTube channel:  https://lnkd.in/gGUG...