https://github.com/imbolc/rttp
Tiny and simple lib for rest http requests
https://github.com/imbolc/rttp
ajax api-client
Last synced: about 1 year ago
JSON representation
Tiny and simple lib for rest http requests
- Host: GitHub
- URL: https://github.com/imbolc/rttp
- Owner: imbolc
- Created: 2015-04-25T06:16:00.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2017-03-20T07:31:26.000Z (about 9 years ago)
- Last Synced: 2025-01-12T02:38:33.905Z (about 1 year ago)
- Topics: ajax, api-client
- Language: JavaScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
rttp
====
rttp is a tiny and simple http requests module
Example
-------
rttp.get('/url')
.success(function (data, xhr) { })
.error(function (data, xhr) { });
.finish(function (data, xhr) { });
API
---
rttp(method, url, data, config)
rttp.get(url, config)
rttp.post(url, data, config)
rttp.put(url, data, config)
rttp.patch(url, data, config)
rttp.del(url, config)
Config options
--------------
- `headers`: [obj], default: `{ 'Content-Type': 'application/json; charset=utf-8' }`
- `dataParser`: function for parsing response data
- `dataDumper`: function for dumping response data
Change defaults
---------------
rttp.setup({
headers: {
// add auth header to each request
Authorization: function () { return 'Bearer ' + localStorage.getItem('auth_token'); },
// remove default Content-Type header
'Content-Type': null
},
// set default error callback
errorCallback: function (data, xhr) {
alert(xhr.status + ': ' + xhr.statusText);
}
// change default data parser
dataParser: function (xhr) { ... },
// change default data dumper
dataDumper: function (data) { ... }
});