main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import axios from 'axios'
import { apply } from 'axios-morphism'

const peopleSchema = {
  name: 'name',
  height: 'height',
  weight: 'mass'
};

const configuration = {
  url: 'https://swapi.co/api/',
  interceptors: {
    responses: [
      { matcher: '/people', schema: peopleSchema, dataSelector: 'results' },
      { matcher: '/people/:id', schema: peopleSchema }
      ],
    requests: []
  }
};

const client = axios.create({baseURL: 'https://swapi.co/api/'});
apply(client, configuration);

client.get('/people/1').then(response => {
  console.log(JSON.stringify(response.data, null, 2))
})
Babel Compiler v6.4.4 Copyright (c) 2014-2015 Sebastian McKenzie