Skip to content

Commit cc934f7

Browse files
committed
Update README.md
1 parent 57c3a26 commit cc934f7

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,12 +2583,28 @@ The core idea behind promises is that a promise represents the result of an asyn
25832583
* rejected - The state of a promise representing a failed operation.
25842584
Once a promise is fulfilled or rejected, it is immutable (i.e. it can never change again).
25852585

2586-
**Creating a Promise:**
2586+
**Example:**
25872587

25882588
```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+
});
25922608
```
25932609

25942610
<div align="right">

0 commit comments

Comments
 (0)