CORS in Backbone.js
Like AngularJS, Backbone.js relies on a separate server application, typically provided by a Node.js server.
If you want to make a CORS
request from a Backbone.js application, you need to modify Backbone.sync, which handles HTTP requests, to add the cross-domain options. You also want to add the withCredentials
property to Backbone.sync for full access to cookies and other information on the target server that are controlled by the same origin policy.
Backbone.sync uses its own syntax for mapping its names for CRUD operations to REST
methods. CRUD is an acronym derived from "create", "read", "update", and "delete". Be mindful of the underlying HTTP method when using Backbone.js syntax for methods, and whether the HTTP method requires preflight
for CORS. Backbone.sync maps its CRUD methods to HTTP methods, as follows:
Backbone.sync Method Name |
REST HTTP Method |
---|---|
create |
POST /collection |
read |
GET /collection[/id] |
update |
PUT /collection/id |
patch |
PATCH /collection/id ... |