File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -3110,6 +3110,34 @@ myPromise
3110
3110
<b><a href="#table-of-contents">↥ back to top</a></b>
3111
3111
</div >
3112
3112
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
+
3113
3141
#### Q. What are async functions in Node?
3114
3142
#### Q. How do you convert an existing callback API to promises?
3115
3143
You can’t perform that action at this time.
0 commit comments