Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve documentation #607

Merged
merged 8 commits into from
Aug 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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