Skip to content

Commit

Permalink
Merge branch 'release/0.7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
steffans committed Jan 25, 2016
2 parents b675df9 + 965976a commit bccab11
Show file tree
Hide file tree
Showing 11 changed files with 277 additions and 186 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build
docs
bower.json
173 changes: 8 additions & 165 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,173 +16,16 @@ var Vue = require('vue');
Vue.use(require('vue-resource'));
```

### Configuration
## Documentation

Set default values using the global configuration.
- [Configuration](docs/config.md)
- [HTTP Requests/Response](docs/http.md)
- [Creating Resources](docs/resource.md)

```js
Vue.http.options.root = '/root';
Vue.http.headers.common['Authorization'] = 'Basic YXBpOnBhc3N3b3Jk';
```

Set default values inside your Vue component options.

```js
new Vue({

http: {
root: '/root',
headers: {
Authorization: 'Basic YXBpOnBhc3N3b3Jk'
}
}

})
```

## HTTP

The http service can be used globally `Vue.http` or in a Vue instance `this.$http`.

### Methods

* `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
* **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
* **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

```js
new Vue({

ready: function() {

// GET 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', response.data)

}, function (response) {

// handle error
});

}

})
```

## Resource
## Changelog

The resource service can be used globally `Vue.resource` or in a Vue instance `this.$resource`.
Details changes for each release are documented in the [release notes](https://github.com/vuejs/vue-resource/releases).

### Methods
## Contribution

* `resource(url, [params], [actions], [options])`

### Default Actions

```js
get: {method: 'GET'},
save: {method: 'POST'},
query: {method: 'GET'},
update: {method: 'PUT'},
remove: {method: 'DELETE'},
delete: {method: 'DELETE'}
```

### Example
```js
new Vue({

ready: function() {

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

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

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

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

}

})
```

## Interceptors

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

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

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

response: function (response) {
return response;
}

});
```

A factory function can also be used.

```js
Vue.http.interceptors.push(function () {
return {

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

response: function (response) {
return response;
}

};
});
```
If you find a bug or want to contribute to the code or documentation, you can help by submitting an [issue](https://github.com/vuejs/vue-resource/issues) or a pull request.
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
"name": "vue-resource",
"main": "dist/vue-resource.js",
"description": "A web request service for Vue.js",
"version": "0.6.1",
"version": "0.7.0",
"homepage": "https://github.com/vuejs/vue-resource",
"license": "MIT",
"ignore": [
".*",
"build",
"docs",
"package.json"
]
}
26 changes: 17 additions & 9 deletions dist/vue-resource.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* vue-resource v0.6.1
* vue-resource v0.7.0
* https://github.com/vuejs/vue-resource
* Released under the MIT License.
*/
Expand Down Expand Up @@ -715,6 +715,7 @@ return /******/ (function(modules) { // webpackBootstrap
params: {},
headers: {},
xhr: null,
upload: null,
jsonp: 'callback',
beforeSend: null,
crossOrigin: null,
Expand Down Expand Up @@ -1157,14 +1158,6 @@ return /******/ (function(modules) { // webpackBootstrap

xhr.open(request.method, _.url(request), true);

if (_.isPlainObject(request.xhr)) {
_.extend(xhr, request.xhr);
}

_.each(request.headers || {}, function (value, header) {
xhr.setRequestHeader(header, value);
});

handler = function (event) {

response.data = xhr.responseText;
Expand All @@ -1175,9 +1168,24 @@ return /******/ (function(modules) { // webpackBootstrap
resolve(response);
};

xhr.timeout = 0;
xhr.onload = handler;
xhr.onabort = handler;
xhr.onerror = handler;
xhr.ontimeout = function () {};
xhr.onprogress = function () {};

if (_.isPlainObject(request.xhr)) {
_.extend(xhr, request.xhr);
}

if (_.isPlainObject(request.upload)) {
_.extend(xhr.upload, request.upload);
}

_.each(request.headers || {}, function (value, header) {
xhr.setRequestHeader(header, value);
});

xhr.send(request.data);
});
Expand Down
Loading

0 comments on commit bccab11

Please sign in to comment.