DEV Community

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

Posted on

1

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);
}));

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay