Skip to content

Commit 120d3ea

Browse files
committed
Update README.md
1 parent 428b968 commit 120d3ea

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3110,6 +3110,34 @@ myPromise
31103110
<b><a href="#table-of-contents">↥ back to top</a></b>
31113111
</div>
31123112

3113+
## Q. How to perform get request using axios in nodejs?
3114+
3115+
```js
3116+
/**
3117+
* Get Request using Axios
3118+
*/
3119+
const express = require("express");
3120+
const app = express();
3121+
const axios = require("axios");
3122+
3123+
app.get("/async", async (req, res) => {
3124+
try {
3125+
const response = await axios.get("https://jsonplaceholder.typicode.com/todos/1");
3126+
res.status(200).json(response.data);
3127+
} catch (err) {
3128+
res.status(500).json({ message: err });
3129+
}
3130+
});
3131+
3132+
app.listen(3000, function () {
3133+
console.log(`App listening at http://localhost:3000/`);
3134+
});
3135+
```
3136+
3137+
<div align="right">
3138+
<b><a href="#table-of-contents">↥ back to top</a></b>
3139+
</div>
3140+
31133141
#### Q. What are async functions in Node?
31143142
#### Q. How do you convert an existing callback API to promises?
31153143

0 commit comments

Comments
 (0)