AYOMIKUN EMMANUEL
devcareers
Published in
4 min readSep 12, 2019

--

POSTMAN: A development tool for managing and executing API

Postman is an API(application programming interface) development tool that helps to build, test and modify APIs and this is done by allowing users to create and save simple and complex HTTP/s requests, as well as read their responses.

In this article, we will build an event API server using express.js and postman will be used to execute the API, but before we do that we need to understand the meaning of node.js, express.js and other dependencies that will be used to achieve this.

Getting started:

What is Node.js?

In simple terms, Node.js is a JavaScript runtime environment that runs outside a browser.

What is Express.js?

Express.js is a web application framework for Node.js and before an express.js can be used, you need Node.js. So, basically, I will say its one of the dependencies used in Node.js.

Build an event API server in the following steps:

  • Create a package.json file in your project
  • Ensure the entry file name of your server is server.js
  • Create a route folder in your project,our route will be handled from there.
  • Create a data folder, inside this folder, an events.js file will be created.
  • Then we test the server in Postman

Installations

Since we will be doing our project in node.js, we need to make sure node.js is installed and its accompanied npm is up to date. So let's create a folder that our project will be stored in, to make it easy this can be done by creating the repository of your project on git and in your VS code, the link of the repository is cloned on your laptop by using git clone <link of repository>

To set up the project, create a package.json, using this command:

  • Install express using <npm install express — save>
  • Install body-parser using <npm install body-parser — save>
  • Install nodemon using <npm install nodemon — save-dev> as this will be helpful in reloading the server automatically whenever a change is made.

Building our server

Create a new file in the root directory called server.js, before creating this file, make sure the default index.js that is assigned to the main string has been replaced with server.js and a start: nodemon server.js to the scripts section. This should look like this:

Then we move to the server.js file where we import the dependencies that have been installed and also set the listener port to 3000. This can be done with:

In the project directory, create a route folder, navigate to the route folder and create a file called route.js, this is where our routes will be handled from. Open up ./routes/routes.js and put this:

Then we move to where we will store our information, under the project directory, open another folder called data, navigate to the ./data folder and create a file called events.js. In this file, we declare our events which will include the name, time, date, location, and id. Open up ./data/events.js and put this:

Okay, I hope I haven’t lost you yet, now we need to start our server using <npm start>, this should be typed in the terminal and you will see a message displayed, it should be like this:

Now we need to test our server and execute our project,this is where postman comes in, and here’s what our GET requests look like i.e to retrieve events. Note that in the URL space localhost:3000/events must be typed in, so as to get the information we need.

Before I round up, I will like to point out that arrow function (ES6) was used in this project, so if you are new to it, you can get more information on it here.

Gotcha, so we’ve fully built an event API server and tested it using postman. If this you like this article, kindly give me a clap and if there’s anything I’ve missed or you not clear about, follow me on twitter @hayycreationz, drop your message in the comments section or send your message to my mail adeolaayo31@yahoo.com.

--

--