{"id":17261704,"url":"https://github.com/petruisfan/ionic-ajax-interceptor","last_synced_at":"2025-06-29T18:03:57.897Z","repository":{"id":58222114,"uuid":"50514464","full_name":"petruisfan/ionic-ajax-interceptor","owner":"petruisfan","description":"Ajax interceptor for $http, designed for ionic","archived":false,"fork":false,"pushed_at":"2017-01-12T00:19:32.000Z","size":29,"stargazers_count":7,"open_issues_count":1,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-14T08:08:30.986Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/petruisfan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-27T14:52:09.000Z","updated_at":"2018-06-27T20:29:08.000Z","dependencies_parsed_at":"2022-09-11T02:10:42.298Z","dependency_job_id":null,"html_url":"https://github.com/petruisfan/ionic-ajax-interceptor","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/petruisfan/ionic-ajax-interceptor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petruisfan%2Fionic-ajax-interceptor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petruisfan%2Fionic-ajax-interceptor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petruisfan%2Fionic-ajax-interceptor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petruisfan%2Fionic-ajax-interceptor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/petruisfan","download_url":"https://codeload.github.com/petruisfan/ionic-ajax-interceptor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petruisfan%2Fionic-ajax-interceptor/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262642959,"owners_count":23341817,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-15T07:51:54.777Z","updated_at":"2025-06-29T18:03:57.864Z","avatar_url":"https://github.com/petruisfan.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ionic-ajax-interceptor\nAjax interceptor for $http, designed for ionic.\n\nThis library is meant to make working with ajax calls much simpler.\nIt's functionalities include:\n - showing a loading screen during http requests\n - caching response data in local storage\n - adding authorization tokens to the request\n - transforming requests and responses\n - default error handler for ui-router\n - fallback ip for cases when dns is not working\n\n## How to use:\n\n1) Install it:\n\n```shell\n$ bower install ionic-ajax-interceptor --save\n```\n\n2) Add the js to your html:\n\n```html\n\u003cscript src=\"lib/ionic-ajax-interceptor/dist/ionic-ajax-interceptor.min.js\"\u003e\u003c/script\u003e\n```\n\n3) Configure your module:\n\n```JavaScript\nangular.module('app', ['ionic', 'ionic-ajax-interceptor'])\n    .config(function( AjaxInterceptorProvider ) {\n        AjaxInterceptorProvider.config({\n            title: \"Bummer\",\n            defaultMessage: \"I crashed :(\",\n            transformRequest: function(data) {\n                data.someKey = \"Some value:\";\n                return data;\n            }\n        });\n    }))\n    .run(function (AjaxInterceptor) {\n        AjaxInterceptor.run();\n        ...\n    })\n```\n\n4) Use it just like $http:\n\n```JavaScript\nvar request = {\n    method: 'GET',\n    url: Constants.endpoint + \"/json\",\n    iCache: {\n        expires: new Date().getTime() + 1000 * 60 // in one minute\n    }\n};\n\nAjaxService.http(request).then(\n    function success(res) {\n        ...\n    },\n    function error(err) {\n        ...    \n    }\n);\n```\n\nNow every time you make a $http request, while the request is in progress, there will be a spinner in front:\n\n![Example](/screenshots/loading.png?raw=true)\n\n## Authorization token\n\n$http requests can have an authorization header added to each request. just do a:\n\n```JavaScript\nAjaxInterceptor.setAuthorizationToken(\u003csome token\u003e);\n```\n\nand all the following request will have a header added automagically :)\n\n## UI-router state change error\n\nEvery time a resolve fails in a state, a $ionicPopup confirm is shown. \nIf the resolve failed and the error argument has a \"message\" key, it will be shown in alert body:\n\n![Example](/screenshots/stateChangeError.png?raw=true)\n\n## Available options:\n\n| Key  | Type | Default | Why? |\n| ---- | ---- | ------- | ---- |\n| stateChangeError | boolean | true | Show a ionic alert every time a \"resolve\" value failed to return in angular-ui-router. | \n| title | string | Error | The title of the alert |\n| defaultMessage | string | Unknown error | The body of the alert | \n| authorizationHeader | string | Authorization | key header to add | \n| authorizationToken | string | null | value of the header |\n| fallbackIp | string | null | Add a fallback ip. For example if the server DNS is not resolved, try to access it by IP. |\n| iCache | Object | null | Add caching capabilities |\n| iCache.key | string | request url | The key under which to save the response |\n| iCache.expires | timestamp | null | When should the cached data expire? Null = never |\n| transformRequest | function | null | Function applied to transform request. Must return the data |\n| transformResponse | function | null | Function applied to transform response. Must return the data |\n\n## Methods\n\n| Name | Arguments | Why? |\n| ---- | --------- | ---- |\n| config | options | Use it in a config block to configure available options mentioned above |\n| run | - | Set the interceptors for $http requests. Call this in the run block before other $http calls |\n| setAuthorizationToken | token | Add an 'authorization' header with token value |\n| showLoading | - | Show the loading screen. Useful for long running tasks or other remote operations like connecting to bluetooth |\n| hideLoading | - | Hide the loading screen |\n\n## AjaxService\n\nAjaxService is a service that can be used the same way as $http, but has the added cache functionality.\nIt has 3 methods:\n- http: replacement for $http\n- clearCache\n- config\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpetruisfan%2Fionic-ajax-interceptor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpetruisfan%2Fionic-ajax-interceptor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpetruisfan%2Fionic-ajax-interceptor/lists"}