feat(docs) Add FAQ about cancelling request · mgonto/restangular@8552c51

Original file line numberDiff line numberDiff line change

@@ -84,6 +84,7 @@ Watch [a video introduction of a talk I gave at Devoxx France](http://www.parley

8484

- [How can I access the unrestangularized element as well as the restangularized one?](#how-can-i-access-the-unrestangularized-element-as-well-as-the-restangularized-one)

8585

- [Restangular fails with status code 0](#restangular-fails-with-status-code-0)

8686

- [Why does this depend on Lodash / Underscore?](#why-does-this-depend-on-lodash--underscore)

87+

- [How do I cancel a request?](#how-do-i-cancel-a-request)

8788

- [Supported Angular versions](#supported-angular-versions)

8889

- [Server Frameworks](#server-frameworks)

8990

- [Releases Notes](#releases-notes)

@@ -1306,6 +1307,24 @@ So, why not use it? If you've never heard of them, by using Restangular, you cou

13061307
13071308

**[Back to top](#table-of-contents)**

13081309
1310+

#### How do I cancel a request?

1311+
1312+

Sometimes you may wish to cancel a request, this is how you would do it:

1313+
1314+

```

1315+

var canceler = $q.defer();

1316+

Restangular.all('users').withHttpConfig({timeout: canceler.promise}).get();

1317+

canceler.resolve(); // cancels the request

1318+

```

1319+
1320+

This is a little counterintuitive, so let me explain. Restangular is built on top of `$http`, which takes a timeout parameter. As per the $http docs:

1321+
1322+

timeout in milliseconds, or promise that should abort the request when resolved.

1323+
1324+

Resolving the promise (canceler in this case), will cancel the request.

1325+
1326+

**[Back to top](#table-of-contents)**

1327+
13091328

# Supported Angular versions

13101329
13111330

Restangular supports all Angular versions from 1.0.X - 1.5.X