{"action":"created","issue":{"url":"https://api.github.com/repos/mzabriskie/axios/issues/320","repository_url":"https://api.github.com/repos/mzabriskie/axios","labels_url":"https://api.github.com/repos/mzabriskie/axios/issues/320/labels{/name}","comments_url":"https://api.github.com/repos/mzabriskie/axios/issues/320/comments","events_url":"https://api.github.com/repos/mzabriskie/axios/issues/320/events","html_url":"https://github.com/mzabriskie/axios/issues/320","id":154780275,"number":320,"title":"Using new keyword / extending axios object?","user":{"login":"reggi","id":296798,"avatar_url":"https://avatars.githubusercontent.com/u/296798?v=3","gravatar_id":"","url":"https://api.github.com/users/reggi","html_url":"https://github.com/reggi","followers_url":"https://api.github.com/users/reggi/followers","following_url":"https://api.github.com/users/reggi/following{/other_user}","gists_url":"https://api.github.com/users/reggi/gists{/gist_id}","starred_url":"https://api.github.com/users/reggi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reggi/subscriptions","organizations_url":"https://api.github.com/users/reggi/orgs","repos_url":"https://api.github.com/users/reggi/repos","events_url":"https://api.github.com/users/reggi/events{/privacy}","received_events_url":"https://api.github.com/users/reggi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-05-13T19:07:40Z","updated_at":"2016-05-14T21:32:02Z","closed_at":null,"body":"I'm interesting in creating an API wrapper and extending from axios using es6 classes. How is this possible? Axios has a method .create() which allows you to generate a new axios object.\r\n\r\n    class Api extends Axios {\r\n      constructor(...args){\r\n        super(..args)\r\n        this.defaults.baseURL = 'https://api.com'\r\n      }\r\n      cancelOrder (id) {\r\n        return this.put(`/cancel/order/${id}`)\r\n      }\r\n    }\r\n\r\nI know I have access to this `let instance = axios.create()`.\r\n\r\nAny thoughts?\r\n\r\n__Attempt 1__\r\n\r\n    import axios from 'axios'\r\n    const Axios = axios.create()\r\n    \r\n    class Api extends Axios {\r\n      constructor (...args) {\r\n        super(...args)\r\n        this.defaults.baseURL = 'https://api.com'\r\n      }\r\n      cancelOrder (id) {\r\n        return this.put(`/cancel/order/${id}`)\r\n      }\r\n    }\r\n    \r\n    let api = new Api()\r\n    \r\n    api.cancelOrder('hi')\r\n      .then(console.log)\r\n      .catch(console.log)\r\n\r\n__Attempt 2__\r\n\r\n    import axios from 'axios'\r\n    \r\n    class Axios {\r\n      constructor () {\r\n        return axios.create()\r\n      }\r\n    }\r\n    \r\n    class Api extends Axios {\r\n      constructor () {\r\n        super()\r\n        this.defaults.baseURL = 'https://api.com'\r\n      }\r\n      cancelOrder (id) {\r\n        return this.put(`/cancel/order/${id}`)\r\n      }\r\n    }\r\n    \r\n    let api = new Api()\r\n    \r\n    console.log(api.__proto__)\r\n    \r\n    api.cancelOrder('hi')\r\n      .then(console.log)\r\n      .catch(console.log)\r\n"},"comment":{"url":"https://api.github.com/repos/mzabriskie/axios/issues/comments/219252724","html_url":"https://github.com/mzabriskie/axios/issues/320#issuecomment-219252724","issue_url":"https://api.github.com/repos/mzabriskie/axios/issues/320","id":219252724,"user":{"login":"reggi","id":296798,"avatar_url":"https://avatars.githubusercontent.com/u/296798?v=3","gravatar_id":"","url":"https://api.github.com/users/reggi","html_url":"https://github.com/reggi","followers_url":"https://api.github.com/users/reggi/followers","following_url":"https://api.github.com/users/reggi/following{/other_user}","gists_url":"https://api.github.com/users/reggi/gists{/gist_id}","starred_url":"https://api.github.com/users/reggi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reggi/subscriptions","organizations_url":"https://api.github.com/users/reggi/orgs","repos_url":"https://api.github.com/users/reggi/repos","events_url":"https://api.github.com/users/reggi/events{/privacy}","received_events_url":"https://api.github.com/users/reggi/received_events","type":"User","site_admin":false},"created_at":"2016-05-14T21:32:02Z","updated_at":"2016-05-14T21:32:02Z","body":"@mikechabot You can see in my comment above that I am trying to add prototype methods, in [this comment](https://github.com/mzabriskie/axios/issues/320#issuecomment-219140706) I have a `.cancelOrder` method. I have a pretty long list of operations and conditions that I currently run on the `instance` of axios I `.create()` including default headers, default bodys, error handling with interceptors and a lot more, all that goes into creating a custom API wrapper and Axios supports out of the box. However I would like to use the syntactic sugar that the es6 class syntax provides to organize my wrapper and `axios` in a clean way other developers that pick up my wrapper will understand as well as use the class syntax to add methods to my custom class rather then adding `.prototype` to the `instance` that axios creates.\r\n\r\nI really don't think this request is too much. All I want is direct access to the code written in the library. Why keep it private / locked away?"}}