A simpler way to call HTTP REST endpoints from a mobile Cordova application.
npm install mobile-simple-rest-callIt uses the best supported database for Cordova, which runs on Android, iOS and Windows platforms (see Cordova Storage documentation for further details).
!Sonarcloud-QualityGate
!Sonarcloud-Security
!Sonarcloud-Quality
!Sonarcloud-Reliability
!Sonarcloud-Vulnerability
 This work is Licensed under GPL v3. You can copy, modify and distribute this software even for commercial purposes; however you must include the reference to the original author and if you modify this software, you must re-distribute it using the same permissive License.
The advantage of this library is having the same behavior across the supoprted platforms and the use of SQLite database. I was motivated to develop this lib due to the inconsistent behavior when communicating with one of our customer's backend as the cache was triggered sometimes in one platform and not in another and the quirks when saving simple key/value data on local database.
HTTP operations:
- GET
- POST
- PUT
- DELETE
For ``GET` operations, the library will take care of caching the server response when needed, avoiding unnecessary network traffic and calls to backend processing routines and extra data usage.
To start a new Cordova project, execute (see https://cordova.apache.org/#getstarted):
`
cordova create MyApp
cd MyApp
cordova platform add
`
``
npm install mobile-simple-rest-call --save
Then copy `node_modules/mobile-simple-rest-call/dist/cordova-simplerestcall.min.js` and `node_modules/jquery/dist/jquery.min.js` to your newly created project under `www/js` directory.
You'll need to import the required libraries on your index.html file and initialize the database:
`html`
Hello World!
> IMPORTANT NOTE: as this library is still being developed, the build is broken right now; I plan to fix the minified file in a couple of days.
To call a REST GET endpoint, you'll need just to call wscall.get(...):
`javascript`
wscall.get(
'http://myserver.org/users/1234',
// (Optional) query strings
null,
function(responseData) {
// Do something when the response is successful
},
function(error) {
// Do something when an error happens
}
);
Similarly, to call a REST POST endpoint you'd invoke:`javascript`
wscall.post(
'http://myserver.org/users',
// Data to be sent
{
"some_data": {
"foo": "bar",
"baz": 0.0,
"nil": null
}
},
function(responseData) {
// Do something when the response is successful
},
function(error) {
// Do something when an error happens
}
);
The same applies to `PUT` and `DELETE`operations:
`javascript`
wscall.put(
'http://myserver.org/users/1234',
// Data to be updated
{
"some_data": {
"foo": "bar",
"baz": 0.0,
"nil": null
}
},
function(responseData) {
// Do something when the response is successful
},
function(error) {
// Do something when an error happens
}
);
`javascript`
wscall.delete(
'http://myserver.org/users/1234',
// (Optional) query strings
null,
function(responseData) {
// Do something when the response is successful
},
function(error) {
// Do something when an error happens
}
);
Contributions are welcome! If you find a bug, or want to suggest an improvement please send me an email at `opensource (at) glauber.me``. You can also fill a bug report on Github and I'll work on it on my free time.
 You can pay me a coffee (:coffee:) or a beer (:beers:) :) I'll be more than happy with your contribution as humble as it is.