DEV Community

Cover image for Take your localhost API to be accessible from WWW
The Ninja Programmer
The Ninja Programmer

Posted on

Take your localhost API to be accessible from WWW

In this post, we will tell you how you can take the API on your machine to be accessible from WWW by using a powerful and free tool called ngrok.

The Problem

Many times we developers develop APIs for our apps. But when we are working in a team and you need to give access to your API to other team members, you just have one option, upload it to a server. This process is very time-consuming.

The Solution

Wouldn't it be easy to simply take the API from localhost to WWW so that anyone could access it? Well, that's exactly what NGrok does for you.

How does it help?

Suppose, I am developing an API that gives me the list of food items. As I am developing it on my machine, the URL to access this would be
Alt Text
Now, I would like my colleague to access this endpoint. So, to do that, I will use ngrok.

Step 1:

Simply visit https://ngrok.com/ and download the ngrok.
Alt Text

Step 2:

Now before using ngrok you have to first set the auth token. So simply go to the ngrok site and get the auth token by creating the account. Now run the below command with your auth token.
Alt Text

Step 3:

Lastly, just run the below command by specifying the port no on which you want to receive the request from WWW.
Alt Text

In My case, it is 80 because my xampp is running on port 80.
Alt Text

Result

Now you will get a random WWW URL from NGROK.
Alt Text
By using this URL anyone can access your localhost API.
Alt Text

Thank you for reading!

Follow us on Instagram
https://www.instagram.com/the.ninja.programmer/

Top comments (3)

Collapse
 
spurwing profile image
Spurwing

Thanks for reminding us of Ngrok!

Collapse
 
natalia_asteria profile image
Natalia Asteria

This method is known as port tunneling, and Ngrok is just one service. There are plenty more better alternatives to Ngrok. You can check them here.

Collapse
 
charalotteyog profile image
Charalotte Yog

Great! Maybe include some detailed Code as well, they are great!