Created
December 2, 2018 20:17
-
-
Save AmrMKayid/75e44dee64f82afe4aa53f471d6724c6 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
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