1const headers = {
2 'Content-Type': 'application/json',
3 'Authorization': 'JWT fefege...'
4}
5
6axios.post(Helper.getUserAPI(), data, {
7 headers: headers
8 })
9 .then((response) => {
10 dispatch({
11 type: FOUND_USER,
12 data: response.data[0]
13 })
14 })
15 .catch((error) => {
16 dispatch({
17 type: ERROR_FINDING_USER
18 })
19 })
1axios.post('url', {"body":data}, {
2 headers: {
3 'Content-Type': 'application/json'
4 }
5 }
6)
1// Send a POST request
2axios({
3 method: 'post',
4 url: '/user/12345',
5 data: {
6 firstName: 'Fred',
7 lastName: 'Flintstone'
8 },
9 headers: {'Authorization': 'Bearer ...'}
10});
1const axios = require('axios');
2
3// httpbin.org gives you the headers in the response
4// body `res.data`.
5// See: https://httpbin.org/#/HTTP_Methods/get_get
6const res = await axios.get('https://httpbin.org/get', {
7 headers: {
8 'Test-Header': 'test-value'
9 }
10});
11
12res.data.headers['Test-Header']; // "test-value"
1let auth = ``; //auth key
2let url = ``; //api url
3
4const axios = require(`axios`);
5axios({
6 method: 'get',
7 url: url,
8 headers: {
9 "Authorization": auth
10 },
11}).then(function (res) {
12 console.log(res.data)
13});
1const username = ''
2const password = ''
3
4const token = Buffer.from(`${username}:${password}`, 'utf8').toString('base64')
5
6const url = 'https://...'
7
8axios.post(url, {
9 headers: {
10 'Authorization': `Basic ${token}`
11 }
12})
13