From d8cce2017d41d6fcdb83ff06d2b7f6d0bb370b20 Mon Sep 17 00:00:00 2001 From: Deric Cain Date: Mon, 8 Jan 2018 06:15:16 -0600 Subject: [PATCH 1/2] Added a simple async/await example Since `async/await` is not widely used, and I have seen quite a few questions on how to actually use `async/await` with Axios, I figured it would be nice to have it in the readme, front and center. --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 95d91e7d86..3a75337d41 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,14 @@ axios.get('/user', { .catch(function (error) { console.log(error); }); + + // Want to use async/await? + try { + const response = axios.get('/user?ID=12345'); + console.log(response); + } catch (error) { + console.log(error); + } ``` Performing a `POST` request From 3ca049924eb492a74c7d2665ebb791ac4c623e44 Mon Sep 17 00:00:00 2001 From: Deric Cain Date: Wed, 21 Feb 2018 08:46:48 -0600 Subject: [PATCH 2/2] Actually added the Async example Also, added notes about using Async/Await with caution --- README.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3a75337d41..b7dd15258e 100644 --- a/README.md +++ b/README.md @@ -74,15 +74,20 @@ axios.get('/user', { console.log(error); }); - // Want to use async/await? +// Want to use async/await? Add the `async` keyword to your outer function/method. +async function getUser() { try { - const response = axios.get('/user?ID=12345'); + const response = await axios.get('/user?ID=12345'); console.log(response); } catch (error) { - console.log(error); + console.error(error); } +} ``` +> **NOTE:** `async/await` is part of ECMAScript 2017 and is not supported in Internet +> Explorer and older browsers, so use with caution. + Performing a `POST` request ```js