How to Test localhost Apis from Public Service ?
How to Test localhost Apis from Public Service ?
As subject said, is there any possible to test localhost Apis from a public service ? Or, imagine another scenario, a team member need to test an api under developing from your machine ?
Now, we have forwarding technique to help us testing our projects more efficiently.
ngrok
-
- Download ngrok toolkit
-
- Signup an ngrok account, and connect it (run it once)
run the command on your cmd line (you can find auth token on your account setup)
ngrok authtoken <your_auth_token>
-
- run it.
ngrok http http://localhost:5000
or
ngrok http 5000
Look, we can now test our api from a public url via ngrok.
localhost.run
First of all, if you are a developer, you might use git for the version control. If yes, you could use ssh now, ssh.exe should stand on your git installed location, .\git\usr\bin. Otherwise, try to use it, that will have a great help for your work.
Of course, this is definitely my prefer forwarding tool.
ssh -R 80:localhost:5000 ssh.localhost.run
Alright, we can test our api from another public url via localhost.run.
If, you face a permission denied error while running ssh tunnel, please follow the guide to correct it.
Serveo
Serveo, another forwarding tool I used it a lot. Unfortunately, the service is down for now. Don't know whether it come back again.
Conclusion
Easy peasy ! With these forwarding tools, team members can test api via localhost machine. Or, we can test Linebot webhook through forwarding tool.
References:
How to test an API running on localhost from outside localhost?
Top 4 BEST Ngrok Alternatives In 2020: Review And Comparison