In this blog, we will set up a REST API implemented using HTTP to play around and understand.
Resources
API endpoint: https://hob-api.vercel.app/
GitHub Repository: https://github.com/sbk2k1/API-Blog
Prerequisites
We will need some tools to get through this blog. They are:
Git/GitHub and npm/yarn(Necessary only if the deployed endpoint is down)
Postman (We can use cURL but Postman will provide us with a cleaner UI)
Installation
Git/GitHub (optional)- Check out my blog!
npm and yarn (optional)- To install npm, follow the below steps:
Download the Node.js installer from here.
Run the installer and follow the installation steps.
Once installed, open a command prompt or terminal and type
npm -v
to check the version of npm.
To install yarn, follow the below steps:
Download the Yarn installer from here.
Run the installer and follow the installation steps.
Once installed, open a command prompt or terminal and type
yarn -v
to check the version of Yarn.
Note: Yarn can also be installed using npm by running the command npm install -g yarn
in the command prompt or terminal.
Postman: To install Postman, you can follow these steps:
Go to the Postman website.
Click the "Download" button for the version of Postman you want to install.
Follow the on-screen instructions to download the installation file.
Once the file is downloaded, open it and follow the instructions to install Postman.
Once the installation is complete, you can launch Postman by opening the application from your computer's application menu or by double-clicking on the Postman icon on your desktop (if you chose to create one during installation).
That's it! You're now ready to use Postman to test and explore APIs.
Setting up a local server (optional)
Follow the following steps to start up a server on your local system:
Clone the repository:
git clone https://github.com/sbk2k1/API-Blog.git
Navigate to the directory:
cd API-Blog
Install dependencies using either npm or yarn:
npm install
or
yarn install
Remove the two forward slashes (
//
) from the beginning of theapp.listen
line to uncomment it.app.listen(3000, () => { console.log(`Server running on port 3000`) });
Add two forward slashes (
//
) at the beginning of themodule.exports = app
the line to comment it out.// module.exports = app;
Once the dependencies are installed, start the server:
npm start
or
yarn start
This will start the server on port 3000 by default.
Getting it to work
Note: I'm going to use the deployed endpoint for the blog, but you can use the http://localhost:3000
if you have it set up in your local system.
/ Route
Create a new request in Postman as shown below:
Fire it off and see what happens.
This is the response.
This signifies that the server is working fine. Note that the status in the top right that says 200 OK. (Status code refresher here)
You can also paste the link into your browser and see what happens. By default, when you enter a URL into a web browser and press enter, it sends a GET request to the server to retrieve the content of the specified resource.
We will look into each route and each little element in greater detail in the next blog. Stay tuned for part 3. If you still have any questions/queries you can reach out to me on my LinkedIn / GitHub / Twitter.
Cheers!