Crud Operation in Postman
In this section, we will:
• Learn about authentication types in APIs.
• Understand common response codes.
• Perform CRUD operations using an Open API, JSONPlaceholder, with step-by-step guidance.
Step 1: Explore JSONPlaceholder
JSONPlaceholder is a free online tool for testing and experimenting with APIs. It provides a set of fake APIs that can be used to practice CRUD operations without impacting any real database.
1. Visit JSONPlaceholder: https://jsonplaceholder.typicode.com
2. Go to the homepage and read the usage guide.
3. Familiarize yourself with endpoints like /posts, /comments, /users.
Step 2: Set Up Postman
Postman is an API testing tool that helps developers execute and verify API requests.
1. Download Postman: https://www.postman.com/downloads/
2. Install the application and create a free account.
• Once logged in, you’re ready to test APIs.
Step 3: Authentication Types
Postman is an API testing tool that helps developers execute and verify API requests.
1. Download Postman: https://www.postman.com/downloads/
2. Install the application and create a free account.
• Once logged in, you’re ready to test APIs.
API Key Authentication
Example: Joget APIs use API keys as query parameters or in headers.
Basic Authentication
Example: Oracle APEX uses Base64-encoded username and password in the header.
Token-Based Authentication
Example: Platforms like Dynamics 365 provide a bearer token to access APIs.
How to Configure in Postman:
1. Go to the Authorization tab.
2. Select the authentication type (API Key, Basic Auth, Bearer Token, etc.).
3. Add the required credentials or tokens.
Step 4: Response Codes and Their Meaning
Example:
While testing APIs, understanding response codes is crucial:
1. 200 OK: Successful request.
2. 201 Created: A resource was created successfully.
3. 400 Bad Request: Invalid syntax in the request.
4. 401 Unauthorized: Authentication failed or missing.
5. 404 Not Found: Requested resource doesn’t exist.
6. 500 Internal Server Error: The server encountered an issue.
Step 5: Perform CRUD Operations Using JSONPlaceholder
We’ll use the JSONPlaceholder API for practice. Here’s how to perform CRUD operations:
1. Create (POST)
API Endpoint: https://jsonplaceholder.typicode.com/posts
Steps in Postman:
1. Select the POST method.
2. In the Body tab, choose raw and set format to JSON.
3. Add data like:
json
{
“title”: “Hello World”,
“body”: “This is a test post.”,
“userId”: 1
}
Click Send and observe the response.
2. Read (GET)
API Endpoint: https://jsonplaceholder.typicode.com/posts/1
Steps in Postman:
1. Select the GET method.
2. Enter the endpoint to fetch a specific post.
3. Click Send and view the response.
json
{
“title”: “Hello World”,
“body”: “This is a test post.”,
“userId”: 1
}
3. Update (PUT)
API Endpoint: https://jsonplaceholder.typicode.com/posts/1
Steps in Postman:
1. Select the PUT method.
2. In the Body tab, provide updated data:
Json
{
“id”: 1,
“title”: “Updated Title”,
“body”: “This post has been updated.”,
“userId”: 1
}
Click Send and observe the changes.
4. Delete (DELETE)
API Endpoint: https://jsonplaceholder.typicode.com/posts/1
Steps in Postman:
1. Select the DELETE method.
2. Enter the endpoint to delete the resource.
3. Click Send and verify the status code 200 OK.
Why Use Postman?
Postman simplifies API testing by:
• Allowing developers to test API functionality before integrating.
• Providing detailed insights into response codes and errors.
• Supporting various authentication types to mimic real-world scenarios.
• Practice and Master APIs
• Follow the steps above to practice API testing using Postman and JSONPlaceholder. Regular practice will help you confidently integrate APIs into your applications.