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 })
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
1// Make a request for a user with a given ID
2axios.get('/user?ID=12345')
3 .then(function (response) {
4 console.log(response);
5 })
6 .catch(function (error) {
7 console.log(error);
8 });
9
10// Optionally the request above could also be done as
11axios.get('/user', {
12 params: {
13 ID: 12345
14 }
15 })
16 .then(function (response) {
17 console.log(response);
18 })
19 .catch(function (error) {
20 console.log(error);
21 });
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 })
20