Created
April 27, 2021 16:40
-
-
Save gaurangrshah/0c0f139ff5552923226199e9f7eafac2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pages/api/my-api-call.js | |
const fetch = require("node-fetch"); | |
export default async (req, res) => { | |
try { | |
const apiCall = await fetch(`http://api-path?api-key=${process.env.SECRET_KEY}`); | |
if (apiCall.response.status === 200) { | |
res.status(200).json({}); | |
res.end(); | |
return res; | |
} | |
} catch (error) { | |
console.log(error); | |
} | |
} | |
// components/MyComponent | |
const myFunction = async () => { | |
const res = await fetch('/api/my-api-call'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment