Notes -2
Notes -2
These applications may access the same database, but they operate independently. They
might even be built using different programming languages. For example:
However, both applications need to communicate. If a ticket is sold out for a route from
Theni to Chennai on the RedBus website, it should be updated on the Tamil Nadu Transport
website. Similarly, if a ticket is sold out or a seat is modified on the Tamil Nadu Transport
website, it should reflect on RedBus in real-time.
So, how do they communicate, even though they are built using different programming
languages?
The answer is JSON/XML, which is used for data exchange. In most REST web services,
JSON is used.
JSON acts like a "translator" between the two websites, ensuring the ticket details are
transferred correctly and keeping both platforms updated.
1. Client – This is anyone or anything that makes a request. It could be a person using a
website or a piece of software asking for information.
2. Server – A program that gets the client’s request, processes it, and sends back a
response.
3. URL (Uniform Resource Locator) – This is the web address you type in a browser
to find something on the internet (like www.example.com).
4. Request – A message from the client to the server asking for some data or action.
5. Response – The message the server sends back to the client after receiving the
request. It could include the data you asked for or an error message.
6. Request Body – This is the information the client sends to the server (like when you
fill out a form and submit it).
7. Response Body – The information the server sends back to the client after it
processes the request (like showing the results of a search).
8. Headers – Extra information that comes with both the request and response, like the
type of data being sent (e.g., JSON or HTML). It’s like the envelope of a letter that
contains important details about the message inside.
9. Content Type – This tells the server what kind of data the client is sending or
receiving. Some examples:
HTTP Methods
The web works with the help of HTTP requests and responses. The backbone of these
requests is HTTP Methods. These methods define the action being requested. Let’s go
through the important ones:
GET
PUT
DELETE
HTTP Response
When the client submits a request, the server responds with:
Status Codes:
1. Endpoint
Where the API sends a request to get or send data. Think of it as the URL address for a
specific feature.
Example (LinkedIn):
• https://api.linkedin.com/v2/users
This endpoint is used to get LinkedIn user data.
2. Path Parameter
Example (LinkedIn):
• https://api.linkedin.com/v2/users/{userId}
Replace {userId} with the actual user ID like 12345:
https://api.linkedin.com/v2/users/12345
This gets the profile of user ID 12345.
3. Query Parameter
Example (LinkedIn):
• https://api.linkedin.com/v2/users?location=India&jobTitle=Engineer
This searches for LinkedIn users in India with the job title Engineer.
4. Header
Additional info sent with a request, like login details or the type of data you want.
Example (LinkedIn):
5. Authentication
Confirms who you are so the server knows you're allowed to use the API. Types:
Now that we know what APIs and web services are, and how HTTP works, let’s connect this
to API Testing.
Expected Output:
1. GET Request
Prerequisites:
Steps:
Expected Output:
<!doctype html>
<html>
<head>...</head>
<body>
<h1>Google</h1>
</body>
</html>
2. POST Request
Dummy Example:
Let’s say we are creating a new user on a dummy API.
Prerequisites:
{
"name": "Yogesh Pandian",
"email": "[email protected]"
}
Steps:
Expected Output:
Response Body:
{
"id": 123,//The unique identifier for the newly created user
(generated by the server)
"name": "Yogesh Pandian",
"email": "[email protected]",
"message": "User created successfully"
}
Dummy Example:
Let’s say we are updating a user’s email address.
Prerequisites:
{
"email": "[email protected]"
}
Steps:
Expected Output:
Response Body:
{
"id": 123,
"name": "Yogesh Pandian",
"email": "[email protected]",
"message": "User updated successfully"
}
4. DELETE Request
Dummy Example:
Let’s say we are deleting a user.
Prerequisites:
• Header: Content-Type: application/json
• Request Method: DELETE
• Endpoint: http://dummyapi/users/123
Steps:
Expected Output:
Response Body:
{
"message": "User deleted successfully"
}
Since no scripts or automation tools (like Selenium or REST Assured) are used to repeat
these tests, it’s manual testing.
Now that we understand API testing, the next step is to write scripts to automate and
repeatedly execute the tests.
Common Misconception:
There is a common misconception that Selenium is the solution for all types of automation.
However, Selenium is specifically designed for automating web applications (UI/browser
automation), not API testing.
HttpUrlConnection
UniRest:
<dependency>
<groupId>com.konghq</groupId>
<artifactId>unirest-java</artifactId>
<version>3.11.11</version>
</dependency>
Rest Assured:
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.2.0</version>
</dependency>