easy-api-js
Easy to use REST calls from browsers - Using the browser fetch API
When not using a buildtool like browserify / webpack and you want to support legacy browsers you'll need polyfills for: fetch, Promise, and Object.assign
npm install easy-api-js
Usage:
// Importvar easyAPI = ; // Define routes// The params in the route will be replaced with values from the // data object that you'll pass when calling a functionvar routes = 'users.save': '/users/save/:id' 'users.delete': '/users/delete/:id' 'users.fetch': '/users/:id'; // Define API functionsvar userAPI = // You can specify a domain function as an object: // this will use the route users.save automatically save: method: 'POST' //route: 'users.save' // optional options: // Optional options applied only to this method call parse: 'blob' // You can define a function instead of a configuration object // to handle calls yourself: //save: function(data) { // let route = this.getRoute('users.save', data}); // return this.post(route, data); //}, { var route = this; return this; }; // Create the APIvar API = '//api.somedomain.com' routes: routes domains: users: userAPI options: // Optional global options given to every call headers: "Authorization": "Basic " + parse: "json" // All fetch Body methods are supported [arrayBuffer, blob, formData, json, text] ; // Anywhere you make the API available you can use it to call your specified functionsAPIusers;