aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIndrajith K L2017-11-02 15:47:14 +0530
committerIndrajith K L2017-11-02 15:47:14 +0530
commita7ccf2688f90f28754b8c61fa0b712d6465d2796 (patch)
tree7c1d7aa19a9ab5349078b0a84e7d4b6e588d2de5
parent70a7e6c3c2019346ea8ad5c52feb464efa0531e5 (diff)
downloades6-backbone-a7ccf2688f90f28754b8c61fa0b712d6465d2796.tar.gz
es6-backbone-a7ccf2688f90f28754b8c61fa0b712d6465d2796.tar.bz2
es6-backbone-a7ccf2688f90f28754b8c61fa0b712d6465d2796.zip
HTTP - Axios integrated
-rw-r--r--package.json3
-rw-r--r--src/http.js14
-rw-r--r--src/index.js7
-rw-r--r--src/myview.js14
-rw-r--r--src/view.js12
5 files changed, 46 insertions, 4 deletions
diff --git a/package.json b/package.json
index f7c89fc..a85476f 100644
--- a/package.json
+++ b/package.json
@@ -27,8 +27,11 @@
"webpack-dev-server": "^2.9.3"
},
"dependencies": {
+ "axios": "^0.17.0",
"backbone": "^1.3.3",
+ "html-loader": "^0.5.1",
"jquery": "^3.2.1",
+ "lodash": "^4.17.4",
"mustache": "^2.3.0",
"underscore": "^1.8.3"
}
diff --git a/src/http.js b/src/http.js
new file mode 100644
index 0000000..355efb2
--- /dev/null
+++ b/src/http.js
@@ -0,0 +1,14 @@
+import axios from 'axios';
+
+class Http {
+ constructor() {
+ this.service = axios.create();
+ }
+
+ set config(configOptions) {
+ this.service = axios.create(configOptions);
+ }
+}
+
+
+export default new Http();
diff --git a/src/index.js b/src/index.js
index f29efc1..68c959b 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,12 +1,17 @@
import Backbone from 'backbone';
import TestView from './view';
import _ from 'underscore';
+import Http from './http';
Backbone.history.start();
class Index {
constructor() {
- new TestView();
+ Http.config = {
+ baseURL: 'http://demo1393194.mockable.io/'
+ };
+ new TestView(); //MainView
+
}
}
diff --git a/src/myview.js b/src/myview.js
index 026f563..d5c0484 100644
--- a/src/myview.js
+++ b/src/myview.js
@@ -1,10 +1,13 @@
import Backbone from 'backbone';
-import * as _ from 'underscore';
+import _ from 'lodash';
import $ from 'jquery';
import Mustache from 'mustache';
+import axios from 'axios';
+import Http from './http';
export default class MyView extends Backbone.View {
+
constructor() {
super();
}
@@ -13,11 +16,18 @@ export default class MyView extends Backbone.View {
this.el = '#myarea';
this.$el = $(this.el);
this.template = 'Hello';
+ Http.service.get('olapa')
+ .then(function (response) {
+ console.log(response);
+ })
+ .catch(function (error) {
+ console.log(error);
+ });
this.render();
+
}
render() {
- console.log(this.el)
this.$el.html(Mustache.render(this.template));
}
diff --git a/src/view.js b/src/view.js
index 399ac03..860148f 100644
--- a/src/view.js
+++ b/src/view.js
@@ -4,6 +4,8 @@ import $ from 'jquery';
import Mustache from 'mustache';
import MyView from './myview';
+import Http from './http';
+
export default class TestView extends Backbone.View {
constructor() {
@@ -13,7 +15,15 @@ export default class TestView extends Backbone.View {
initialize() {
this.el = 'li';
this.$el = $(this.el);
- this.template = '<div id="myarea"></div>'
+ this.template = '<div id="myarea"></div>';
+
+ Http.service.get('test1').then(function (response) {
+ console.log(response);
+ })
+ .catch(function (error) {
+ console.log(error);
+ });
+
this.render();
}