DEV Community

Cover image for How to Post data json use apikey
Angga Lesmana
Angga Lesmana

Posted on

How to Post data json use apikey

I will share to you about my experience although not too much
but i hope this is important for you as javascript developer

const axios = require('axios');
const express = require('express');

const app = express();

var postData = {
'this':'this data will you post'
}

let axiosConfig = {
headers: {
'Authorization': 'Bearer your-apikey',
'Response-Format': 'JSON',
'Content-Type': 'application/json',
"Access-Control-Allow-Origin": "*",
}
};

axios.post('https://link apikey', postData, axiosConfig)
.then((res) => {
console.log(RESPONSE RECEIVED: ${postData}, res);
})
.catch((err) => {
console.log("AXIOS ERROR: ", err);
})

axios.get('https://link apikey')
.then(response => {
console.log(response.data.created_at);
});

try {

} catch (error) {

}
Enter fullscreen mode Exit fullscreen mode

axios.all([
axios.get('https://link apikey'),
axios.get('https://link apikey')
])
.then(axios.spread((user1, user2) => {
console.log('Date created: ', user1.data.created_at);
console.log('Date created: ', user2.data.created_at);
}));

Top comments (0)