Using Postman

Using Postman

We can use Postman, or similar tools such as Insomnia, to test our API endpoints. Postman provides a user-friendly interface for sending requests to your server and inspecting the responses. It allows you to test different HTTP methods, headers, and request bodies easily.

Set up our server

Create a new project and set up a simple server using the following code:

index.js:

javascript
	const http = require('http');
	
	const server = http.createServer((req, res) => {
	  res.writeHead(200, { 'Content-Type': 'text/plain' });
	  res.end('Hello, World!\n');
	});
	
	server.listen(3000, () => {
	  console.log('Server running at http://localhost:3000/');
	});

Test the Endpoint with Postman

  1. Open Postman and create a new request to http://localhost:3000.

  2. Select the HTTP method (GET) and click the “Send” button.

  3. You should see the response “Hello, World!” in the response body.

Postman GET request

Lesson task

We will use Postman to help develop and test our API points.

Goal

Demonstrate you can use Postman or similar tools.

Brief

  1. Create a server with a root / end-point that sends a custom message.

  2. Create a collection in Postman and add a request to test the / end-point.

NOTE: Lesson tasks do not get submitted on Moodle and are not assessed by tutors. They are mainly there for you to practise what you have learned in the lesson.