I have an api like this:
app.get('/test', (req, res) => {
console.log("this is test");
});
and another api:
app.get('/check', (req, res) => {
//I want to call "test" api without redirect to it.
});
I want to call "test" api in "check" api without redirect to "test" api, just do the function in the "test" api. Above is the example code. 'Cause I dont' want to rewrite function from "test" api to "check"
This approach isn't limited to your API; you can use it to call any API. Your Express application needs to be able to call the API URLs that you set up in chapter 6—sending the correct request method, of course—and then be able to interpret the response. To help, you'll use a module called request .
Simple solution is to define a method which can be called using both request routes.
app.get('/test', (req, res) => {
console.log("this is test");
callMeMayBe();
});
callMeMayBe()
{
//Your code here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With