File tree Expand file tree Collapse file tree 1 file changed +20
-4
lines changed Expand file tree Collapse file tree 1 file changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -2583,12 +2583,28 @@ The core idea behind promises is that a promise represents the result of an asyn
2583
2583
* rejected - The state of a promise representing a failed operation.
2584
2584
Once a promise is fulfilled or rejected, it is immutable (i.e. it can never change again).
2585
2585
2586
- ** Creating a Promise :**
2586
+ ** Example :**
2587
2587
2588
2588
``` js
2589
- const myPromise = new Promise (function (resolve , reject ){
2590
- ... .
2591
- })
2589
+ /**
2590
+ * GET Request using Axios
2591
+ */
2592
+ const express = require (" express" );
2593
+ const app = express ();
2594
+ const axios = require (" axios" );
2595
+
2596
+ app .get (" /" , async (req , res ) => {
2597
+ try {
2598
+ const response = await axios .get (" https://jsonplaceholder.typicode.com/todos/1" );
2599
+ res .status (200 ).json (response .data );
2600
+ } catch (err) {
2601
+ res .status (500 ).json ({ message: err });
2602
+ }
2603
+ });
2604
+
2605
+ app .listen (3000 , function () {
2606
+ console .log (` App listening at http://localhost:3000/` );
2607
+ });
2592
2608
```
2593
2609
2594
2610
<div align =" right " >
You can’t perform that action at this time.
0 commit comments