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)
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"
1axios.post(
2'https://example.com/postSomething',
3{ // this is the body
4 email: varEmail,
5 password: varPassword
6},
7{
8 headers: {
9 Authorization: 'Bearer ' + varToken
10 }
11})
12
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
1// Send a POST request
2axios({
3 method: 'post',
4 url: '/user/12345',
5 data: {
6 firstName: 'Fred',
7 lastName: 'Flintstone'
8 }
9});