Skip to content

Commit

Permalink
Merge pull request #607 from marmelab/improve_doc
Browse files Browse the repository at this point in the history
Improve documentation
  • Loading branch information
fzaninotto committed Aug 23, 2015
2 parents 316fcf6 + b0b7d98 commit f42983e
Show file tree
Hide file tree
Showing 25 changed files with 1,741 additions and 882 deletions.
968 changes: 101 additions & 867 deletions README.md

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions doc/API-mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Now if your API returns results in another format, for instance with all the val
You can use Restangular element transformers to map that to the expected format:

```js
app.config(function(RestangularProvider) {
myApp.config(function(RestangularProvider) {
RestangularProvider.addElementTransformer('books', function(element) {
for (var key in element.values) {
element[key] = element.values[key];
Expand All @@ -66,7 +66,7 @@ app.config(function(RestangularProvider) {
Symetrically, if your API requires that you post and put data inside of a `values` field, use Restangular request interceptor:

```js
app.config(function(RestangularProvider) {
myApp.config(function(RestangularProvider) {
RestangularProvider.addFullRequestInterceptor(function(element, operation, what, url, headers, params, httpConfig) {
if(operation == 'post' || operation == 'put') {
element = { values: element };
Expand Down Expand Up @@ -115,7 +115,7 @@ http://your.api.domain/entityName?_page=2&_perPage=20
For instance, to use `offset` and `limit` instead of `_page` and `_perPage` across the entire application, use the following code:
```js
app.config(function(RestangularProvider) {
myApp.config(function(RestangularProvider) {
RestangularProvider.addFullRequestInterceptor(function(element, operation, what, url, headers, params, httpConfig) {
if (operation == 'getList' && what == 'entityName') {
params.offset = (params._page - 1) * params._perPage;
Expand Down Expand Up @@ -159,7 +159,7 @@ If your API doesn't return a `X-Total-Count` header, you can add a `totalCount`
Add the following response interceptor:
```js
app.config(function(RestangularProvider) {
myApp.config(function(RestangularProvider) {
RestangularProvider.addResponseInterceptor(function(data, operation, what, url, response) {
if (operation == "getList") {
var contentRange = response.headers('Content-Range');
Expand All @@ -181,7 +181,7 @@ http://your.api.domain/entityName?_sortField=name&_sortDir=ASC
Once again, you can change it with a response interceptor. For instance, to sort by `id desc` by default, and without changing the name of the sort query parameters, use:
```js
app.config(function(RestangularProvider) {
myApp.config(function(RestangularProvider) {
RestangularProvider.addFullRequestInterceptor(function(element, operation, what, url, headers, params, httpConfig) {
if (operation == 'getList' && what == 'entityName') {
params._sortField = params._sortField || 'id';
Expand Down Expand Up @@ -213,7 +213,7 @@ Where the `_filters` value is the url encoded version of `{"q":"foo","tag":"bar"
Just like other query params, you can transform it using a Restangular request interceptor. For instance, to pass all filters directly as query parameters:
```js
app.config(function(RestangularProvider) {
myApp.config(function(RestangularProvider) {
RestangularProvider.addFullRequestInterceptor(function(element, operation, what, url, headers, params, httpConfig) {
if (operation == 'getList' && what == 'entityName') {
if (params._filters) {
Expand Down
Loading

0 comments on commit f42983e

Please sign in to comment.