|
Postman, a popular API development and testing tool allowing developers to interact with APIs. In this guide, we’ll explore the basics of testing API endpoints using Postman and Express, providing clear steps and examples. Prerequisites:
Steps to test API endpoints with Postman & Express:Step 1: Create a basic Express application and install the required dependencies. npm init -y Folder Structure: Folder Structure The updated dependencies in package.json file will look like: "dependencies": { Step 2: Create a file named `server.js` and add the following code:
Run your server with the following command and access it at `http://localhost:3000`: node server.js Step 3: Create a New Request Open Postman, click “New,” and select ” Add Request.” Give it a name and save it in a collection. ![]() Creating Collection and new request Step 4: Define Request Details Enter the request URL. For example, use `http://localhost:3000/hello`. Select the HTTP method (GET) from the dropdown menu. ![]() Setting url and method type Step 5: Click “Send” to make the request. ![]() Send button Step 6: Getting the response from server. For `/hello`, the response should be “Hello, Postman!”. You will get this in Response window at bottom. ![]() Response from server Step 7: Test Other Endpoints Repeat the process for `/greet/:name` and `/calculate`. Adjust the URL and request method accordingly.
![]() Sending params in url
![]() Output GIF:
|
Reffered: https://www.geeksforgeeks.org
Express.js |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |