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

Commit

Permalink
merge release v0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
steffans committed Dec 20, 2015
2 parents 03c7b55 + e6b4d64 commit e78afc1
Show file tree
Hide file tree
Showing 34 changed files with 2,240 additions and 719 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/node_modules
/test/specs.js
.DS_Store
100 changes: 76 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,27 @@ The http service can be used globally `Vue.http` or in a Vue instance `this.$htt

### Methods

* `get(url, [data], [success], [options])`
* `post(url, [data], [success], [options])`
* `put(url, [data], [success], [options])`
* `patch(url, [data], [success], [options])`
* `delete(url, [data], [success], [options])`
* `jsonp(url, [data], [success], [options])`
* `get(url, [data], [options])`
* `post(url, [data], [options])`
* `put(url, [data], [options])`
* `patch(url, [data], [options])`
* `delete(url, [data], [options])`
* `jsonp(url, [data], [options])`

### Options

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


### Example

Expand All @@ -76,14 +76,24 @@ new Vue({
ready: function() {

// GET request
this.$http.get('/someUrl', function (data, status, request) {
this.$http.get('/someUrl').then(function (response) {

// get status
response.status;

// get all headers
response.headers();

// get 'expires' header
response.headers('expires');

// set data on vm
this.$set('someData', data)
this.$set('someData', response.data)

}, function (response) {

}).error(function (data, status, request) {
// handle error
})
});

}

Expand Down Expand Up @@ -115,28 +125,70 @@ new Vue({

ready: function() {

var resource = this.$resource('someItem/:id');
var resource = this.$resource('someItem{/id}');

// get item
resource.get({id: 1}, function (item, status, request) {
this.$set('item', item)
})
resource.get({id: 1}).then(function (response) {
this.$set('item', response.item)
});

// save item
resource.save({id: 1}, {item: this.item}, function (data, status, request) {
resource.save({id: 1}, {item: this.item}).then(function (response) {
// handle success
}).error(function (data, status, request) {
}, function (response) {
// handle error
})
});

// delete item
resource.delete({id: 1}, function (data, status, request) {
resource.delete({id: 1}).then(function (response) {
// handle success
}).error(function (data, status, request) {
}, function (response) {
// handle error
})
});

}

})
```

## Interceptors

Interceptors can be defined globally and are used for pre- and postprocessing of a request.

```javascript
Vue.http.interceptors.push({

request: function (request) {
return request;
},

response: function (response) {
return response;
}

});
```

#### Interceptor Factory

If Promises are needed inside of a Interceptor, a factory function can be used.

```javascript
Vue.http.interceptors.push(function (Promise) {
return {

request: function (request) {
if (reject) {
return Promise.reject();
}
},

response: function (response) {
if (reject) {
return Promise.reject();
}
}

};
});
```
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vue-resource",
"main": "dist/vue-resource.js",
"description": "A web request service for Vue.js",
"version": "0.1.17",
"version": "0.5.0",
"homepage": "https://github.com/vuejs/vue-resource",
"license": "MIT",
"ignore": [
Expand Down
Loading

0 comments on commit e78afc1

Please sign in to comment.