Skip to content

Instantly share code, notes, and snippets.

@gaurangrshah
Created April 27, 2021 16:40
Show Gist options
  • Save gaurangrshah/0c0f139ff5552923226199e9f7eafac2 to your computer and use it in GitHub Desktop.
Save gaurangrshah/0c0f139ff5552923226199e9f7eafac2 to your computer and use it in GitHub Desktop.
// 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