Skip to content

Commit 82de3f7

Browse files
author
sw-yx
committed
switch to axios
1 parent 9077884 commit 82de3f7

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.4.0",
44
"private": true,
55
"dependencies": {
6-
"node-fetch": "^2.3.0",
6+
"axios": "^0.19.0",
77
"react": "^16.8.6",
88
"react-dom": "^16.8.6",
99
"react-scripts": "^3.0.0"

src/lambda/async-dadjoke.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
// example of async handler using async-await
22
// https://github.com/netlify/netlify-lambda/issues/43#issuecomment-444618311
33

4-
import fetch from "node-fetch"
4+
import axios from "axios"
55
export async function handler(event, context) {
66
try {
7-
const response = await fetch("https://icanhazdadjoke.com", { headers: { Accept: "application/json" } })
8-
if (!response.ok) {
9-
// NOT res.status >= 200 && res.status < 300
10-
return { statusCode: response.status, body: response.statusText }
11-
}
12-
const data = await response.json()
13-
7+
const response = await axios.get("https://icanhazdadjoke.com", { headers: { Accept: "application/json" } })
8+
const data = response.data
149
return {
1510
statusCode: 200,
1611
body: JSON.stringify({ msg: data.joke })

yarn.lock

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2188,6 +2188,14 @@ aws4@^1.8.0:
21882188
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f"
21892189
integrity sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==
21902190

2191+
axios@^0.19.0:
2192+
version "0.19.0"
2193+
resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.0.tgz#8e09bff3d9122e133f7b8101c8fbdd00ed3d2ab8"
2194+
integrity sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==
2195+
dependencies:
2196+
follow-redirects "1.5.10"
2197+
is-buffer "^2.0.2"
2198+
21912199
axobject-query@^2.0.2:
21922200
version "2.0.2"
21932201
resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-2.0.2.tgz#ea187abe5b9002b377f925d8bf7d1c561adf38f9"
@@ -4472,6 +4480,13 @@ flush-write-stream@^1.0.0:
44724480
inherits "^2.0.1"
44734481
readable-stream "^2.0.4"
44744482

4483+
follow-redirects@1.5.10:
4484+
version "1.5.10"
4485+
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a"
4486+
integrity sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==
4487+
dependencies:
4488+
debug "=3.1.0"
4489+
44754490
follow-redirects@^1.0.0:
44764491
version "1.6.1"
44774492
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.6.1.tgz#514973c44b5757368bad8bddfe52f81f015c94cb"
@@ -5312,7 +5327,7 @@ is-buffer@^1.0.2, is-buffer@^1.1.5:
53125327
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"
53135328
integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==
53145329

5315-
is-buffer@^2.0.0:
5330+
is-buffer@^2.0.0, is-buffer@^2.0.2:
53165331
version "2.0.3"
53175332
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-2.0.3.tgz#4ecf3fcf749cbd1e472689e109ac66261a25e725"
53185333
integrity sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw==
@@ -6840,11 +6855,6 @@ no-case@^2.2.0:
68406855
dependencies:
68416856
lower-case "^1.1.1"
68426857

6843-
node-fetch@^2.3.0:
6844-
version "2.3.0"
6845-
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.3.0.tgz#1a1d940bbfb916a1d3e0219f037e89e71f8c5fa5"
6846-
integrity sha512-MOd8pV3fxENbryESLgVIeaGKrdl+uaYhCSSVkjeOb/31/njTpcis5aWfdqgNlHIrKOLRbMnfPINPOML2CIFeXA==
6847-
68486858
node-forge@0.7.5:
68496859
version "0.7.5"
68506860
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.7.5.tgz#6c152c345ce11c52f465c2abd957e8639cd674df"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy