0% found this document useful (0 votes)
5 views6 pages

Tool Postman 08.07.24 With Testing - Services WEB Restful Building B 2 Exp

The document outlines a procedure for building RESTful web services using Node.js and testing them with the Postman tool. It includes steps for installing Node.js, setting up a project, creating an Express application, and testing API endpoints. The process concludes with a successful demonstration of retrieving book data via Postman.

Uploaded by

jiteshraaju
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

Tool Postman 08.07.24 With Testing - Services WEB Restful Building B 2 Exp

The document outlines a procedure for building RESTful web services using Node.js and testing them with the Postman tool. It includes steps for installing Node.js, setting up a project, creating an Express application, and testing API endpoints. The process concludes with a successful demonstration of retrieving book data via Postman.

Uploaded by

jiteshraaju
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

JITESHRAAJU

R 22IT038

Exp 2B BUILDING RESTFULWEB SERVICES- TESTING WITH

08.07.24 POSTMAN TOOL

AIM:
To bulid RESTful web services and testing it with Postman Tool.
PROCEDURE:

1. Install Node.js by clicking the below link.


https://nodejs.org/en/download/prebuilt-installer

2. After installing Node.js you could getSetup Wizard in that click Next.

3. Click Install.

4. Click Finish.
JITESHRAAJU
R 22IT038

After installation completed.

1. Open Command Prompt and type the Command

Cmd – node - v

Cmd – npm - v
To check Installations

2. Type the command

Cmd – init -y
JITESHRAAJU
R 22IT038

3. After running the above command now you could see package.json file the
directory

4. Type the command

Cmd – npm install express nodemon


JITESHRAAJU
R 22IT038

5. Create a file index.js with the following code. const express =

require('express'); // This line imports the Express module const Joi =


require('joi'); // used for validation const app = express(); // creates an
instance of express application const bodyParser = require('body-parser'); //
parse incoming request bodies app.use(express.json()); // express
application will use inbuilt json function

const books = [
{ title: 'Harry Potter', id: 1 },
{ title: 'Twilight', id: 2 },
{ title: 'Lorien Legacies', id: 3 } ];
// defines array of books

app.get('/', (req, res) =>


{ res.send('REST APIs are so much
fun'); }); // route handler – sends a
response

app.get('/api/books', (req, res) =>


{ res.send(books);
});

app.get('/api/books/:id', (req, res) => { const book = books.find(c =>


c.id === parseInt(req.params.id)); if (!book)
{ res.status(404).send( '<h2 style="font-family: Malgun Gothic;
color: darkred;">Ooops... Cant find what you are looking for!</h2>'); }
res.send(book);
});
JITESHRAAJU
R 22IT038

const port = process.env.PORT || 8081;


app.listen(port, () => console.log(`Listening on port ${port}..`));

After saving the file type node 1.js in the command prompt.

7. Download the postman tool from the below link


https://www.postman.com/downloads /

8. Now Type the http://localhost:8081/api/books / and Get and click Send button.
JITESHRAAJU
R 22IT038

9. You could get the output below.

RESULT:
Thus building a RESTful web services and testing it with Postman Tool is
completed successfully.

You might also like