API Testing

What is API Testing ?
As we know API stands for Application Programming Interface which acts as an intermediate of communication between two applications. Due to this intermediary role of API (Application Programming Interface) two applications talk to each other and performs the required actions efficiently. API contains a set of rules and guidelines based on which the applications are developed. So in simple we can say an API acts as an interface between two software applications so that two software applications can communicate with each other.

API Testing Methods

POST

GET

PUT

PATCH

DELETE

● OPTIONS

● HEAD

● TRACE

● CONNECT

● COPY

● LINK

● UNLINK

● PURGE

● LOCK

● UNLOCK

● PROPFIND

● VIEW

API Data Input Formats :

● Text – Text(text/Plain)

● JSON (application/json)

● Javascript (application/javascript)

● XML (application/xml) – XML (text/xml)

● HTML (text/html)

 

HTTP Status Codes

1. Informational responses (100 – 199)

2. Successful responses (200 – 299)

3. Redirection messages (300 – 399)

4. Client error responses (400 – 499)

5. Server error responses (500 – 599)

1xx Informational

100 Continue

101 Switching Protocols

102 Processing (WebDAV)

2xx Success

200 OK

201 Created

202 Accepted

203 Non-Authoritative Information

204 No Content

205 Reset Content

206 Partial Content

207 Multi-Status (WebDAV)

208 Already Reported (WebDAV)

226 IM Used

3xx Redirection

300 Multiple Choices

301 Moved Permanently

302 Found

303 See Other

304 Not Modified

305 Use Proxy

306 (Unused)

307 Temporary Redirect

308 Permanent Redirect (experimental)

4xx Client Error

400 Bad Request

401 Unauthorized

402 Payment Required

403 Forbidden

404 Page Not Found

405 Method Not Allowed

406 Not Acceptable

407 Proxy Authentication Required

408 Request Timeout

409 Conflict

410 Gone

411 Length Required

412 Precondition Failed

413 Request Entity Too Large

414 Request-URI Too Long

415 Unsupported Media Type

416 Requested Range Not Satisfiable

417 Expectation Failed

418 I’m a teapot (RFC 2324)

420 Enhance Your Calm (Twitter)

422 Unprocessable Entity (WebDAV)

423 Locked (WebDAV)

424 Failed Dependency (WebDAV)

425 Reserved for WebDAV

426 Upgrade Required

428 Precondition Required

429 Too Many Requests

431 Request Header Fields Too Large

444 No Response (Nginx)

449 Retry With (Microsoft)

450 Blocked by Windows Parental Controls (Microsoft)

451 Unavailable For Legal Reasons

499 Client Closed Request (Nginx)

5xx Server Error

500 Internal Server Error

501 Not Implemented

502 Bad Gateway

503 Service Unavailable

504 Gateway Timeout

505 HTTP Version Not Supported

506 Variant Also Negotiates (Experimental)

507 Insufficient Storage (WebDAV)

508 Loop Detected (WebDAV)

509 Bandwidth Limit Exceeded (Apache)

510 Not Extended

511 Network Authentication Required

598 Network read timeout error

599 Network connect timeout error

Create Bulk Data for Json Formate :

{
    “operations”: [
        {
            “id”: “13”,
            “email”: “techlearn.india@gmail.com“,
            “first_name”: “tech”,
            “last_name”: “learn”,
            “avatar”: “https://
techlearn.in/img/faces/techlearn-image.jpg”
        },
        {
            “id”: “14”,
            “email”: “seleniumlearn.com@gmail.com“,
            “first_name”: “selenium”,
            “last_name”: “learn”,
            “avatar”:”https://
techlearn.in/img/faces/seleniumlearn-image.jpg”
        }
    ]
}

API Testing Notes

HTTP Methods in API Development and Testing:

HTTP (Hypertext Transfer Protocol) specifies a collection of request methods to specify what action is to be performed on a particular resource. The most commonly used HTTP request methods are GET, POST, PUT, PATCH, and DELETE. These are equivalent to the CRUD operations (create, read, update, and delete).

1. GET

The GET method is used to ‘retrieve’ a record or a collection of records from the server.

GET request is used to read/retrieve data from a web server. GET returns an HTTP status code of 200 (OK) if the data is successfully retrieved from the server.

2. POST

The POST method sends data to create a ‘new record‘ on the server.

POST request is used to send data (file, form data, etc.) to the server. On successful creation, it returns an HTTP status code of 201.

3. PUT

The PUT method sends data to update an ‘existing record‘ on the server.

A PUT request is used to modify the data on the server. It replaces the entire content at a particular location with data that is passed in the body payload. If there are no resources that match the request, it will generate one.

4. PATCH

Like the PUT method, PATCH is also used to send data to update an ‘existing record’ on the server. But the important difference between PUT and PATCH is that PATCH only applies partial modifications to the record instead of replacing the whole record.

PATCH is similar to PUT request, but the only difference is, it modifies a part of the data. It will only replace the content that you want to update.

5. DELETE

The DELETE method is used to delete record(s) from the server.

A DELETE request is used to delete the data on the server at a specified location.