Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@moos/backbone-fetch

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@moos/backbone-fetch

Backbone Models without jQuery.ajax

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

backbone-fetch

Backbone Model CRUD operations using ES6 fetch API. Can be used without jQuery or jQuery.ajax.

Install

npm i @moos/backbone-fetch

Or get it from jsDelivr CDN...

Latest:

Versioned (recommemded in production):

Usage

require('backbone');
Backbone.ajax = require('@moos/backbone-fetch'); // or use <scrip> 

let model = new Backbone.Model({foo: 1});
model.save()
  .then(response => {...})
  .catch(error => {...});

Similar for other Backbone CRUD operations: fetch() & destroy().

Note: it returns an ES6 Promise. Use polyfill for older browsers.

To pass body and headers:

model.save(null, {
  data: {...}  // JSON data to pass in HTTP body
  headers: {
    'Accept': 'application/json'
  }
})
  .then(response => {...})
  .catch(error => {...});

If AbortController is supported (sorry IE or use a polyfill), the returned promise will have an abort() method:

var promise = model.fetch();
// a little later...
promise.abort();

The success of abort depends on the state of the fetch call at the time abort was called. According to AbortController/abort() docs, "when abort() is called, the fetch() promise rejects with an AbortError."

Change log

  • 1.0 Initial release

License

ICS

Keywords

FAQs

Package last updated on 14 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc