Skip to content

Instantly share code, notes, and snippets.

@AmrMKayid
Created December 2, 2018 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AmrMKayid/75e44dee64f82afe4aa53f471d6724c6 to your computer and use it in GitHub Desktop.
Save AmrMKayid/75e44dee64f82afe4aa53f471d6724c6 to your computer and use it in GitHub Desktop.
require('isomorphic-fetch');
const mongoose = require('mongoose');
module.exports.TakeFromAPI = async (req, res, next) => {
const headers = new Headers();
headers.append('Content-Type', 'application/json');
// Hena el json object elli htb3teh ll API
const JSON_TO_SEND_TO_API = {
"<KEY>": '<VALUE>',
"<KEY>": '<VALUE>',
"<KEY>": '<VALUE>',
};
// Di el result elli htgelk mn el Amazon API
const result = await fetch(<AMAZON_API_URL>, {
body: JSON.stringify(JSON_TO_SEND_TO_API),
method: 'POST',
mode: 'cors',
headers,
});
// Bn7wl el result hena to JSON format 3lshan n3mlha save
const result_json_response = await result.json();
// TRY this line 3lshan tshofi el response howa elli f postman wala la2
console.log(result_json_response);
// B3d kda el mafrod ykon 3ndk schema shabh el response 3lshan t3mli save f el db
<SCHEMA>.create(result_json_response);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment