Skip to content
This repository was archived by the owner on Dec 1, 2023. It is now read-only.

Commit e78afc1

Browse files
committed
merge release v0.5.0
2 parents 03c7b55 + e6b4d64 commit e78afc1

34 files changed

+2240
-719
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/node_modules
2+
/test/specs.js
23
.DS_Store

README.md

Lines changed: 76 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,27 @@ The http service can be used globally `Vue.http` or in a Vue instance `this.$htt
4646

4747
### Methods
4848

49-
* `get(url, [data], [success], [options])`
50-
* `post(url, [data], [success], [options])`
51-
* `put(url, [data], [success], [options])`
52-
* `patch(url, [data], [success], [options])`
53-
* `delete(url, [data], [success], [options])`
54-
* `jsonp(url, [data], [success], [options])`
49+
* `get(url, [data], [options])`
50+
* `post(url, [data], [options])`
51+
* `put(url, [data], [options])`
52+
* `patch(url, [data], [options])`
53+
* `delete(url, [data], [options])`
54+
* `jsonp(url, [data], [options])`
5555

5656
### Options
5757

5858
* **url** - `string` - URL to which the request is sent
59-
* **data** - `Object|string` - Data to be sent as the request message data
6059
* **method** - `string` - HTTP method (e.g. GET, POST, ...)
60+
* **data** - `Object|string` - Data to be sent as the request message data
6161
* **params** - `Object` - Parameters object to be appended as GET parameters
6262
* **headers** - `Object` - Headers object to be sent as HTTP request headers
63-
* **success** - `function(data, status, request)` - Callback function to be called when the request finishes
64-
* **error** - `function(data, status, request)` - Callback function to be called when the request fails
65-
* **beforeSend** - `function(request, options)` - Callback function to modify the request object before it is sent
63+
* **beforeSend** - `function(request)` - Callback function to modify the request object before it is sent
6664
* **emulateHTTP** - `boolean` - Send PUT, PATCH and DELETE requests with a HTTP POST and set the `X-HTTP-Method-Override` header
6765
* **emulateJSON** - `boolean` - Send request data as `application/x-www-form-urlencoded` content type
6866
* **xhr** - `Object` - Parameters object to be set on the native XHR object
6967
* **jsonp** - `string` - Callback function name in a JSONP request
68+
* **timeout** - `number` - Request timeout in milliseconds (`0` means no timeout)
69+
7070

7171
### Example
7272

@@ -76,14 +76,24 @@ new Vue({
7676
ready: function() {
7777

7878
// GET request
79-
this.$http.get('/someUrl', function (data, status, request) {
79+
this.$http.get('/someUrl').then(function (response) {
80+
81+
// get status
82+
response.status;
83+
84+
// get all headers
85+
response.headers();
86+
87+
// get 'expires' header
88+
response.headers('expires');
8089

8190
// set data on vm
82-
this.$set('someData', data)
91+
this.$set('someData', response.data)
92+
93+
}, function (response) {
8394

84-
}).error(function (data, status, request) {
8595
// handle error
86-
})
96+
});
8797

8898
}
8999

@@ -115,28 +125,70 @@ new Vue({
115125

116126
ready: function() {
117127

118-
var resource = this.$resource('someItem/:id');
128+
var resource = this.$resource('someItem{/id}');
119129

120130
// get item
121-
resource.get({id: 1}, function (item, status, request) {
122-
this.$set('item', item)
123-
})
131+
resource.get({id: 1}).then(function (response) {
132+
this.$set('item', response.item)
133+
});
124134

125135
// save item
126-
resource.save({id: 1}, {item: this.item}, function (data, status, request) {
136+
resource.save({id: 1}, {item: this.item}).then(function (response) {
127137
// handle success
128-
}).error(function (data, status, request) {
138+
}, function (response) {
129139
// handle error
130-
})
140+
});
131141

132142
// delete item
133-
resource.delete({id: 1}, function (data, status, request) {
143+
resource.delete({id: 1}).then(function (response) {
134144
// handle success
135-
}).error(function (data, status, request) {
145+
}, function (response) {
136146
// handle error
137-
})
147+
});
138148

139149
}
140150

141151
})
142152
```
153+
154+
## Interceptors
155+
156+
Interceptors can be defined globally and are used for pre- and postprocessing of a request.
157+
158+
```javascript
159+
Vue.http.interceptors.push({
160+
161+
request: function (request) {
162+
return request;
163+
},
164+
165+
response: function (response) {
166+
return response;
167+
}
168+
169+
});
170+
```
171+
172+
#### Interceptor Factory
173+
174+
If Promises are needed inside of a Interceptor, a factory function can be used.
175+
176+
```javascript
177+
Vue.http.interceptors.push(function (Promise) {
178+
return {
179+
180+
request: function (request) {
181+
if (reject) {
182+
return Promise.reject();
183+
}
184+
},
185+
186+
response: function (response) {
187+
if (reject) {
188+
return Promise.reject();
189+
}
190+
}
191+
192+
};
193+
});
194+
```

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vue-resource",
33
"main": "dist/vue-resource.js",
44
"description": "A web request service for Vue.js",
5-
"version": "0.1.17",
5+
"version": "0.5.0",
66
"homepage": "https://github.com/vuejs/vue-resource",
77
"license": "MIT",
88
"ignore": [

0 commit comments

Comments
 (0)