### Example Usage Source: https://github.com/pagekit/vue-resource/blob/develop/docs/resource.md Illustrates how to use the Resource service with default actions for GET, POST, and DELETE requests. ```APIDOC ## Example Usage ### Description Demonstrates making various HTTP requests using the default actions of the Resource service. ### Request Examples ```javascript // Define a resource for 'someItem' var resource = this.$resource('someItem{/id}'); // GET request to fetch an item by ID resource.get({id: 1}).then(response => { this.item = response.body; }); // POST request to save an item resource.save({id: 1}, {item: this.item}).then(response => { // success callback }, response => { // error callback }); // DELETE request to remove an item by ID resource.delete({id: 1}).then(response => { // success callback }, response => { // error callback }); ``` ``` -------------------------------- ### Vue Resource Basic Usage Example Source: https://github.com/pagekit/vue-resource/blob/develop/docs/resource.md Demonstrates how to create and use a Vue Resource instance for making GET, POST, and DELETE requests to an API. It shows how to handle responses and errors. ```javascript var resource = this.$resource('someItem{/id}'); // GET someItem/1 resource.get({id: 1}).then(response => { this.item = response.body; }); // POST someItem/1 resource.save({id: 1}, {item: this.item}).then(response => { // success callback }, response => { // error callback }); // DELETE someItem/1 resource.delete({id: 1}).then(response => { // success callback }, response => { // error callback }); ``` -------------------------------- ### Vue Resource Request Examples Source: https://github.com/pagekit/vue-resource/blob/develop/docs/http.md Illustrates various use cases for making HTTP requests, including POST requests with a JSON body, GET requests with query parameters and custom headers, and fetching binary data like images using the `blob()` method. ```APIDOC ## Vue Resource Request Examples Here are several examples demonstrating common use cases for the Vue Resource http service. ### POST Request with JSON Body ```js // POST /someUrl with body { "foo": "bar" } this.$http.post('/someUrl', {foo: 'bar'}).then(response => { // Access response properties console.log(response.status); console.log(response.statusText); console.log(response.headers.get('Expires')); this.someData = response.body; }, response => { // error callback }); ``` ### GET Request with Query Parameters and Custom Headers ```js // GET /someUrl?foo=bar with custom header 'X-Custom: ...' this.$http.get('/someUrl', {params: {foo: 'bar'}, headers: {'X-Custom': '...'}}).then(response => { // success callback }, response => { // error callback }); ``` ### Fetching Binary Data (Image) with blob() ```js // GET /image.jpg, expecting a blob response this.$http.get('/image.jpg', {responseType: 'blob'}).then(response => { // Resolve the response body as a Blob return response.blob(); }).then(blob => { // Use the image Blob object // For example, to display the image: // const imgUrl = URL.createObjectURL(blob); // const img = document.createElement('img'); // img.src = imgUrl; // document.body.appendChild(img); }); ``` ``` -------------------------------- ### Install vue-resource with npm or yarn Source: https://github.com/pagekit/vue-resource/blob/develop/README.md Demonstrates how to add the vue-resource package to your project using either npm or yarn package managers. ```bash $ yarn add vue-resource $ npm install vue-resource ``` -------------------------------- ### Vue Instance POST Request Example Source: https://github.com/pagekit/vue-resource/blob/develop/docs/http.md Provides an example of making a POST request with data using the $http service in a Vue instance. It demonstrates how to access response properties like status, statusText, headers, and body. ```javascript { // POST /someUrl this.$http.post('/someUrl', {foo: 'bar'}).then(response => { // get status response.status; // get status text response.statusText; // get 'Expires' header response.headers.get('Expires'); // get body data this.someData = response.body; }, response => { // error callback }); } ``` -------------------------------- ### Vue Resource Custom Actions Example Source: https://github.com/pagekit/vue-resource/blob/develop/docs/resource.md Illustrates how to define and use custom actions for specific API endpoints with Vue Resource, including GET and POST requests with custom URLs. ```javascript var customActions = { foo: {method: 'GET', url: 'someItem/foo{/id}'}, bar: {method: 'POST', url: 'someItem/bar{/id}'} } var resource = this.$resource('someItem{/id}', {}, customActions); // GET someItem/foo/1 resource.foo({id: 1}).then(response => { this.item = response.body; }); // POST someItem/bar/1 resource.bar({id: 1}, {item: this.item}).then(response => { // success callback }, response => { // error callback }); ``` -------------------------------- ### Perform a GET request with vue-resource Source: https://github.com/pagekit/vue-resource/blob/develop/README.md Illustrates making a GET request to a specified URL and handling the response using Promises. It shows how to access the response body or handle errors. ```javascript { // GET /someUrl this.$http.get('/someUrl').then(response => { // get body data this.someData = response.body; }, response => { // error callback }); } ``` -------------------------------- ### HTTP GET with Query Parameters and Headers Source: https://github.com/pagekit/vue-resource/blob/develop/docs/http.md Shows how to send a GET request with URL query parameters and custom headers using the $http service. The configuration object is used to specify parameters and headers. ```javascript { // GET /someUrl?foo=bar this.$http.get('/someUrl', {params: {foo: 'bar'}, headers: {'X-Custom': '...'}}).then(response => { // success callback }, response => { // error callback }); } ``` -------------------------------- ### Custom Actions with URL Parameters Source: https://github.com/pagekit/vue-resource/blob/develop/docs/resource.md Provides an example of correctly passing URL parameters for custom POST actions. ```APIDOC ## Custom Actions with URL Parameters ### Description Illustrates how to correctly send URL parameters when using custom POST actions, especially when the default behavior might interpret the object as a body parameter. ### Example ```javascript // Define a resource with a custom 'baz' POST action var resource = this.$resource('someItem{/id}', {}, { baz: { method: 'POST', url: 'someItem/baz{/id}' } }); // POST to 'someItem/baz' (assuming no ID is needed for this specific call, or ID is part of the base URL) // The params object `{}` is used to ensure the first argument is treated as URL parameters (even if empty) and the second argument is the body. resource.baz({ id: 1 }).then(response => { // success callback }, response => { // error callback }); // POST to 'someItem/baz/1' where '1' is the ID in the URL // An empty object `{}` is passed as the second argument to signify that no body parameters are being sent, allowing the `{id: 1}` to be correctly mapped to the URL. resource.baz({ id: 1 }, {}).then(response => { // success callback }, response => { // error callback }); ``` ``` -------------------------------- ### Vue Resource Interceptor Examples Source: https://github.com/pagekit/vue-resource/blob/develop/docs/http.md Demonstrates how to implement interceptors for global request and response processing. Interceptors allow for pre-processing of requests (e.g., adding authentication headers) and post-processing of responses. ```APIDOC ## Vue Resource Interceptors Interceptors provide a mechanism to globally intercept requests before they are sent or responses before they are handled. This is useful for tasks like adding authentication tokens or logging. ### Request Interceptor Example This interceptor modifies outgoing requests by setting custom headers, such as CSRF tokens or authorization Bearer tokens. ```js Vue.http.interceptors.push(function(request) { // Modify request method request.method = 'POST'; // Set custom headers request.headers.set('X-CSRF-TOKEN', 'YOUR_CSRF_TOKEN'); request.headers.set('Authorization', 'Bearer YOUR_ACCESS_TOKEN'); // Return the modified request or a promise resolving to it return request; }); ``` ### Request and Response Interceptor Example This interceptor demonstrates modifying both the request before it's sent and the response after it's received. The response callback can be used to transform response data. ```js Vue.http.interceptors.push(function(request) { // Modify request before sending request.method = 'POST'; // Return a callback function to process the response return function(response) { // Modify response body response.body = 'Processed: ' + response.body; // Return the modified response return response; }; }); ``` ``` -------------------------------- ### Global and Instance HTTP Methods Source: https://github.com/pagekit/vue-resource/blob/develop/docs/http.md Illustrates the usage of shortcut methods for different HTTP request types (GET, POST) both globally via Vue.http and within a Vue instance via this.$http. Configuration and callback parameters are shown. ```javascript // global Vue object Vue.http.get('/someUrl', [config]).then(successCallback, errorCallback); Vue.http.post('/someUrl', [body], [config]).then(successCallback, errorCallback); // in a Vue instance this.$http.get('/someUrl', [config]).then(successCallback, errorCallback); this.$http.post('/someUrl', [body], [config]).then(successCallback, errorCallback); ``` -------------------------------- ### Integrate Vue-Resource with Webpack/Browserify Source: https://github.com/pagekit/vue-resource/blob/develop/docs/config.md Instructions for adding Vue-Resource to a project using npm and integrating it with module bundlers like Webpack or Browserify. This involves installing the package and using `Vue.use()`. ```javascript var Vue = require('vue'); var VueResource = require('vue-resource'); Vue.use(VueResource); ``` -------------------------------- ### Vue Resource HTTP Methods Source: https://github.com/pagekit/vue-resource/blob/develop/docs/http.md Provides a list of shortcut methods available for various HTTP request types, including GET, HEAD, DELETE, JSONP, POST, PUT, and PATCH. These methods can be used globally or within a Vue instance. ```APIDOC ## Vue Resource HTTP Methods Vue Resource offers shortcut methods for common HTTP request types. These can be invoked globally using `Vue.http` or on a Vue instance using `this.$http`. ### Available Methods * `get(url, [config])` * `head(url, [config])` * `delete(url, [config])` * `jsonp(url, [config])` * `post(url, [body], [config])` * `put(url, [body], [config])` * `patch(url, [body], [config])` ### Method Signature Examples ```js // Global Vue object Vue.http.get('/someUrl', [config]).then(successCallback, errorCallback); Vue.http.post('/someUrl', [body], [config]).then(successCallback, errorCallback); // In a Vue instance this.$http.get('/someUrl', [config]).then(successCallback, errorCallback); this.$http.post('/someUrl', [body], [config]).then(successCallback, errorCallback); ``` ``` -------------------------------- ### Vue Instance HTTP Request Source: https://github.com/pagekit/vue-resource/blob/develop/docs/http.md Demonstrates sending a GET request using the $http service within a Vue instance. It shows how to handle both successful responses and errors using Promises. ```javascript { // GET /someUrl this.$http.get('/someUrl').then(response => { // success callback }, response => { // error callback }); } ``` -------------------------------- ### Vue Resource Default Actions Source: https://github.com/pagekit/vue-resource/blob/develop/docs/resource.md Defines the default actions for RESTful HTTP methods (GET, POST, PUT, DELETE) that can be used with Vue Resource. ```javascript get: {method: 'GET'}, save: {method: 'POST'}, query: {method: 'GET'}, update: {method: 'PUT'}, remove: {method: 'DELETE'}, delete: {method: 'DELETE'} ``` -------------------------------- ### Fetching Image Blob with responseType Source: https://github.com/pagekit/vue-resource/blob/develop/docs/http.md Demonstrates fetching an image file using a GET request and processing the response as a Blob. It utilizes the `responseType: 'blob'` option and the `response.blob()` method. ```javascript { // GET /image.jpg this.$http.get('/image.jpg', {responseType: 'blob'}).then(response => { // resolve to Blob return response.blob(); }).then(blob => { // use image Blob }); } ``` -------------------------------- ### Global Request Interceptor Source: https://github.com/pagekit/vue-resource/blob/develop/docs/http.md Illustrates how to add a global interceptor to modify outgoing requests. This example shows how to change the request method and set custom headers like CSRF token and authorization. ```javascript Vue.http.interceptors.push(function(request) { // modify method request.method = 'POST'; // modify headers request.headers.set('X-CSRF-TOKEN', 'TOKEN'); request.headers.set('Authorization', 'Bearer TOKEN'); }); ``` -------------------------------- ### Include vue-resource via CDN Source: https://github.com/pagekit/vue-resource/blob/develop/README.md Shows how to include the vue-resource library in an HTML file using a Content Delivery Network (CDN) link. ```html ``` -------------------------------- ### Resource Service Overview Source: https://github.com/pagekit/vue-resource/blob/develop/docs/resource.md The Resource service can be used globally via `Vue.resource` or within a Vue instance as `this.$resource`. ```APIDOC ## Resource Service ### Description The Resource service provides a way to define reusable resource endpoints for making HTTP requests. ### Usage It can be accessed globally as `Vue.resource` or within a Vue instance as `this.$resource`. ### Method Signature `resource(url, [params], [actions], [options])` - **url**: The URL template for the resource. Path parameters can be defined using `{/param}` syntax. - **params**: Default query parameters to be sent with requests. - **actions**: Custom actions to define specific HTTP methods and their configurations. - **options**: Global options for the resource requests. ``` -------------------------------- ### Custom Actions Source: https://github.com/pagekit/vue-resource/blob/develop/docs/resource.md Shows how to define and use custom actions for specific HTTP methods and URLs. ```APIDOC ## Custom Actions ### Description Allows defining custom HTTP methods and their corresponding URLs beyond the default actions. ### Example ```javascript // Define custom actions 'foo' (GET) and 'bar' (POST) var customActions = { foo: { method: 'GET', url: 'someItem/foo{/id}' }, bar: { method: 'POST', url: 'someItem/bar{/id}' } }; // Create a resource with custom actions var resource = this.$resource('someItem{/id}', {}, customActions); // Execute the custom 'foo' action (GET) resource.foo({id: 1}).then(response => { this.item = response.body; }); // Execute the custom 'bar' action (POST) resource.bar({id: 1}, { item: this.item }).then(response => { // success callback }, response => { // error callback }); ``` ### Note on Custom Actions When providing a single object for POST, PUT, and PATCH custom actions, it defaults to the request body. To specify URL parameters, an empty object must be passed as the second argument. ``` -------------------------------- ### Default Actions Source: https://github.com/pagekit/vue-resource/blob/develop/docs/resource.md The Resource service comes with a set of default actions that map to common HTTP methods. ```APIDOC ## Default Actions ### Description These are the predefined actions available for a resource. ### Actions - **get**: `{method: 'GET'}` - **save**: `{method: 'POST'}` - **query**: `{method: 'GET'}` - **update**: `{method: 'PUT'}` - **remove**: `{method: 'DELETE'}` - **delete**: `{method: 'DELETE'}` ``` -------------------------------- ### Vue Resource HTTP Configuration Source: https://github.com/pagekit/vue-resource/blob/develop/docs/http.md Details the configuration options available for HTTP requests, including URL, body, headers, query parameters, method type, response type, timeout, credentials, emulation settings, and callbacks for request/upload/download progress. ```APIDOC ## Vue Resource HTTP Configuration Requests can be customized using a `config` object passed as an argument. This object allows for fine-grained control over various aspects of the HTTP request. ### Configuration Parameters | Parameter | Type | Description | |------------------|-----------------------------|------------------------------------------------------------------------------------------------------------| | `url` | `string` | The URL to which the request is sent. | | `body` | `Object`, `FormData`, `string` | Data to be sent as the request body. | | `headers` | `Object` | An object containing custom HTTP headers to be sent with the request. | | `params` | `Object` | An object containing parameters to be sent as URL query parameters. | | `method` | `string` | The HTTP method to use for the request (e.g., GET, POST, PUT, DELETE). | | `responseType` | `string` | Specifies the expected type of the response body (e.g., 'text', 'blob', 'json'). | | `timeout` | `number` | The request timeout in milliseconds. A value of `0` indicates no timeout. | | `credentials` | `boolean` | If `true`, enables cross-site Access-Control requests using credentials. | | `emulateHTTP` | `boolean` | If `true`, emulates PUT, PATCH, and DELETE requests by sending them as POST requests with an `X-HTTP-Method-Override` header. | | `emulateJSON` | `boolean` | If `true`, sends the request body with the `application/x-www-form-urlencoded` content type. | | `before` | `function(request)` | A callback function executed before the request is sent, allowing modification of the request object. | | `uploadProgress` | `function(event)` | A callback function to handle the [ProgressEvent](https://developer.mozilla.org/en-US/docs/Web/API/ProgressEvent) during uploads. | | `downloadProgress`| `function(event)` | A callback function to handle the [ProgressEvent](https://developer.mozilla.org/en-US/docs/Web/API/ProgressEvent) during downloads. | ``` -------------------------------- ### Vue Resource Custom POST with URL Params Source: https://github.com/pagekit/vue-resource/blob/develop/docs/resource.md Shows how to correctly perform a POST request with Vue Resource when URL parameters are needed, by providing an empty object as the second argument. ```javascript var resource = this.$resource('someItem{/id}', {}, { baz: {method: 'POST', url: 'someItem/baz{/id}'} }); // POST someItem/baz resource.baz({id: 1}).then(response => { // success callback }, response => { // error callback }); // POST someItem/baz/1 resource.baz({id: 1}, {}).then(response => { // success callback }, response => { // error callback }); ``` -------------------------------- ### Emulate HTTP Methods for Legacy Web Servers in Vue-Resource Source: https://github.com/pagekit/vue-resource/blob/develop/docs/config.md Enable the `emulateHTTP` option to override unsupported HTTP methods like PUT, PATCH, and DELETE. This uses the `X-HTTP-Method-Override` header with a POST request. ```javascript Vue.http.options.emulateHTTP = true; ``` -------------------------------- ### Vue Resource HTTP Service Usage Source: https://github.com/pagekit/vue-resource/blob/develop/docs/http.md Demonstrates how to access and use the http service globally via `Vue.http` or within a Vue instance via `this.$http` to send HTTP requests. Request methods return a Promise that resolves to the response. ```APIDOC ## Vue Resource HTTP Service Usage The `http` service in Vue Resource can be accessed globally through `Vue.http` or on a Vue instance as `this.$http`. It allows you to send HTTP requests and returns a Promise that resolves to the response. ### Usage within a Vue Instance ```js // GET /someUrl this.$http.get('/someUrl').then(response => { // success callback }, response => { // error callback }); ``` ### Global Usage ```js // GET /someUrl Vue.http.get('/someUrl').then(response => { // success callback }, response => { // error callback }); ``` ``` -------------------------------- ### Vue-Resource Headers Object Source: https://github.com/pagekit/vue-resource/blob/develop/docs/api.md Details the properties and methods of the Headers object for managing HTTP headers. ```APIDOC ## Vue-Resource Headers Object ### Description Manages HTTP headers for requests and responses. ### Properties - **map** (object) - An object containing the headers. ### Methods - **has(string: name)** (boolean) - Checks if a header exists. - **get(string: name)** (string) - Retrieves the value of a header. - **getAll()** (string[]) - Retrieves all header values. - **set(string: name, string: value)** (void) - Sets a header. - **append(string: name, string: value)** (void) - Appends a header value. - **delete(string: name)** (void) - Deletes a header. - **forEach(function: callback, any: thisArg)** (void) - Iterates over the headers. ``` -------------------------------- ### Emulate JSON for Legacy Web Servers in Vue-Resource Source: https://github.com/pagekit/vue-resource/blob/develop/docs/config.md Enable the `emulateJSON` option to send requests with `application/x-www-form-urlencoded` MIME type if the web server cannot handle `application/json` encoding. ```javascript Vue.http.options.emulateJSON = true; ``` -------------------------------- ### Abort Previous Request with Vue-Resource Source: https://github.com/pagekit/vue-resource/blob/develop/docs/recipes.md This recipe demonstrates how to abort a previously sent request when a new one is initiated, which is useful for scenarios like autocomplete inputs. It uses the `before` callback to manage and cancel ongoing requests. This prevents outdated data from being processed. ```javascript { // GET /someUrl this.$http.get('/someUrl', { // use before callback before(request) { // abort previous request, if exists if (this.previousRequest) { this.previousRequest.abort(); } // set previous request on Vue instance this.previousRequest = request; } }).then(response => { // success callback }, response => { // error callback }); } ``` -------------------------------- ### Vue-Resource Headers Object Source: https://github.com/pagekit/vue-resource/blob/develop/docs/api.md Outlines the constructor, properties, and methods for the Headers object in Vue-Resource. This object manages HTTP headers, providing functionality to access, modify, and iterate over header key-value pairs. ```javascript { // Constructor constructor(object: headers) // Properties map (object) // Methods has(string: name) (boolean) get(string: name) (string) getAll() (string[]) set(string: name, string: value) (void) append(string: name, string: value) (void) delete(string: name) (void) forEach(function: callback, any: thisArg) (void) } ``` -------------------------------- ### Vue-Resource Response Object Source: https://github.com/pagekit/vue-resource/blob/develop/docs/api.md Details the constructor, properties, and methods for the Response object in Vue-Resource. This object represents the server's reply to an HTTP request, including body, status, and headers, with methods to parse the response body. ```javascript { // Constructor constructor(any: body, object: {string: url, object: headers, number: status, string: statusText}) // Properties url (string) body (any) headers (Headers) ok (boolean) status (number) statusText (string) // Methods blob() (Promise) text() (Promise) json() (Promise) } ``` -------------------------------- ### Vue-Resource Request Object Source: https://github.com/pagekit/vue-resource/blob/develop/docs/api.md Details the properties and methods of the Request object used for making HTTP requests. ```APIDOC ## Vue-Resource Request Object ### Description Represents an outgoing HTTP request. ### Properties - **url** (string) - The URL for the request. - **body** (any) - The request body. - **headers** (Headers) - The request headers. - **method** (string) - The HTTP method (e.g., GET, POST). - **params** (object) - URL query parameters. - **timeout** (number) - Request timeout in milliseconds. - **credentials** (boolean) - Whether to include credentials. - **emulateHTTP** (boolean) - Whether to emulate HTTP methods. - **emulateJSON** (boolean) - Whether to emulate JSON data. - **before** (function(Request)) - Callback function executed before the request is sent. - **progress** (function(Event)) - Callback function for tracking upload progress. ### Methods - **getUrl()** (string) - Returns the request URL. - **getBody()** (any) - Returns the request body. - **respondWith(any: body, object: config)** (Response) - Responds to the request with a given body and configuration. - **abort()** - Aborts the request. ``` -------------------------------- ### Set Global Default Configuration for Vue-Resource Source: https://github.com/pagekit/vue-resource/blob/develop/docs/config.md Configure default settings for Vue-Resource globally using `Vue.http.options`. This includes setting a base URL for requests and default headers, such as authorization. ```javascript Vue.http.options.root = '/root'; Vue.http.headers.common['Authorization'] = 'Basic YXBpOnBhc3N3b3Jk'; ``` -------------------------------- ### Submit Form Data with FormData using Vue-Resource Source: https://github.com/pagekit/vue-resource/blob/develop/docs/recipes.md This recipe shows how to send form data using the FormData API with Vue-Resource. It demonstrates appending string values and file objects to the FormData instance before sending a POST request. Ensure that FormData is supported in your environment. ```javascript { var formData = new FormData(); // append string formData.append('foo', 'bar'); // append Blob/File object formData.append('pic', fileInput, 'mypic.jpg'); // POST /someUrl this.$http.post('/someUrl', formData).then(response => { // success callback }, response => { // error callback }); } ``` -------------------------------- ### Request and Response Interceptor Source: https://github.com/pagekit/vue-resource/blob/develop/docs/http.md Shows how to implement an interceptor that modifies both the outgoing request and the incoming response. It demonstrates changing the request method and modifying the response body. ```javascript Vue.http.interceptors.push(function(request) { // modify request request.method = 'POST'; // return response callback return function(response) { // modify response response.body = '...'; }; }); ``` -------------------------------- ### Vue-Resource Request Object Source: https://github.com/pagekit/vue-resource/blob/develop/docs/api.md Defines the constructor, properties, and methods for the Request object in Vue-Resource. This object manages the details of an HTTP request, including URL, body, headers, and request lifecycle hooks. ```javascript { // Constructor constructor(object: config) // Properties url (string) body (any) headers (Headers) method (string) params (object) timeout (number) credentials (boolean) emulateHTTP (boolean) emulateJSON (boolean) before (function(Request)) progress (function(Event)) // Methods getUrl() (string) getBody() (any) respondWith(any: body, object: config) (Response) abort() } ``` -------------------------------- ### Vue Resource Response Handling Source: https://github.com/pagekit/vue-resource/blob/develop/docs/http.md Describes the structure of the response object returned by HTTP requests, including properties like URL, body, headers, status, and methods for parsing the response body such as `text()`, `json()`, and `blob()`. ```APIDOC ## Vue Resource Response Handling When an HTTP request is successful, the Promise resolves to a response object. This object contains detailed information about the response and provides methods for accessing the response body in different formats. ### Response Object Properties | Property | Type | Description | |---------------|-----------------------------|----------------------------------------------------------------| | `url` | `string` | The URL from which the response originated. | | `body` | `Object`, `Blob`, `string` | The actual data content of the response body. | | `headers` | `Header` | An object representing the response headers. | | `ok` | `boolean` | Indicates if the HTTP status code is between 200 and 299. | | `status` | `number` | The HTTP status code of the response. | | `statusText` | `string` | The HTTP status text associated with the status code. | ### Response Body Parsing Methods | Method | Type | Description | |-------------|----------|-------------------------------------------------------------| | `text()` | `Promise`| Resolves the response body as a plain string. | | `json()` | `Promise`| Resolves the response body as a parsed JSON object. | | `blob()` | `Promise`| Resolves the response body as a Blob object. | ``` -------------------------------- ### Vue-Resource Response Object Source: https://github.com/pagekit/vue-resource/blob/develop/docs/api.md Details the properties and methods of the Response object received from an HTTP request. ```APIDOC ## Vue-Resource Response Object ### Description Represents an incoming HTTP response. ### Properties - **url** (string) - The URL of the response. - **body** (any) - The response body. - **headers** (Headers) - The response headers. - **ok** (boolean) - Indicates if the response status is in the 2xx range. - **status** (number) - The HTTP status code. - **statusText** (string) - The HTTP status text. ### Methods - **blob()** (Promise) - Returns the response body as a Blob. - **text()** (Promise) - Returns the response body as text. - **json()** (Promise) - Returns the response body as JSON. ``` -------------------------------- ### Return Response and Stop Processing with Vue-Resource Interceptor Source: https://github.com/pagekit/vue-resource/blob/develop/docs/http.md This snippet demonstrates how to register an interceptor that intercepts a request, modifies it, and then stops further processing by returning a custom response. It's useful for handling specific scenarios like returning a mock response or error. ```javascript Vue.http.interceptors.push(function(request) { // modify request ... // stop and return response return request.respondWith(body, { status: 404, statusText: 'Not found' }); }); ``` -------------------------------- ### Set Component-Level Default Configuration for Vue-Resource Source: https://github.com/pagekit/vue-resource/blob/develop/docs/config.md Configure default settings for Vue-Resource within a Vue component's options. This allows for more localized configuration compared to global settings. ```javascript new Vue({ http: { root: '/root', headers: { Authorization: 'Basic YXBpOnBhc3N3b3Jk' } } }) ``` -------------------------------- ### Override Default Vue-Resource Interceptor ('before') Source: https://github.com/pagekit/vue-resource/blob/develop/docs/http.md This snippet shows how to override the default 'before' interceptor in Vue-Resource. This allows customization of the pre-request processing logic, such as adding headers or validating requests before they are sent. ```javascript Vue.http.interceptor.before = function(request) { // override before interceptor }; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.