Registry / devops / can-define-rest-model

can-define-rest-model

JSON →
library2.0.0jsnpmunverified

Connect a DefineMap to a RESTful API endpoint. Version 2.0.0 is the latest stable release of this CanJS plugin. It provides a declarative way to define REST models using can-define and can-connect. The package is actively maintained by Bitovi and follows CanJS's release cadence. Unlike raw can-connect, it integrates tightly with can-define's property definitions and provides automatic CRUD methods.

npm install can-define-rest-model
INSTALL
IMPORT
SIG · CAN-DEFINE-REST-MO
C
can-define-rest-model
devopsjavascriptv2.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

DefineMap
import DefineMap from 'can-define/map/map'
const { DefineMap } = require('can-define')
DefineMap is a default export from can-define/map/map; in CJS use const DefineMap = require('can-define/map/map').
defineRestModel
import defineRestModel from 'can-define-rest-model'
const { defineRestModel } = require('can-define-rest-model')
defineRestModel is a default export of the package; named import will be undefined.
restModel functions
DefineMap.extend('model', {}, { defineRestModel: { ... } }) or use defineRestModel constructor
import { restModel } from 'can-define-rest-model'
There is no named export 'restModel'. Use the default export defineRestModel and pass a DefineMap.

Demonstrates defining a RESTful model with Todo list using can-define-rest-model, including CRUD URL configuration and getList usage.

import DefineMap from 'can-define/map/map'; import defineRestModel from 'can-define-rest-model'; const Todo = DefineMap.extend('Todo', { id: { type: 'number', identity: true }, name: 'string', complete: { type: 'boolean', default: false } }, { defineRestModel: { url: '/api/todos/{id}', findAll: 'GET /api/todos', findOne: 'GET /api/todos/{id}', create: 'POST /api/todos', update: 'PUT /api/todos/{id}', destroy: 'DELETE /api/todos/{id}' } }); // Usage Todo.getList({}).then(todos => console.log(todos));
Debug
Known issues
breakingIn version 2.0, defineRestModel expects a DefineMap with an identity property (typically 'id'). Without an identity property, model operations may fail.
fix
Ensure your DefineMap has an identity property: id: { type: 'number', identity: true }.
affects: >=2.0
deprecatedThe package previously exported 'restModel' as a named export; this was removed in 2.0. Use default export 'defineRestModel'.
fix
Change import from import { restModel } from 'can-define-rest-model' to import defineRestModel from 'can-define-rest-model'.
affects: >=2.0
gotchaIf you define a model without specifying all aliases (findAll, findOne, etc.), it may fall back to default behavior that might not match your API.
fix
Explicitly define all CRUD aliases or ensure the defaults match your API endpoints.
affects: >=1.0
Errors
Common errors & fixes
TypeError: Cannot read property 'url' of undefined
Missing defineRestModel configuration object or incorrect import.
fix
Ensure you import defineRestModel correctly and pass a config object with url property.
Error: No identity property found on map
The DefineMap does not have a property with identity: true.
fix
Add an identity property, e.g., id: { type: 'number', identity: true }.
Module not found: Can't resolve 'can-define/map/map'
can-define is not installed or path is incorrect.
fix
Install can-define: npm install can-define. Ensure import path matches.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
can-connectrequiredprovides the underlying connection logic
can-definerequiredrequired for DefineMap and property definitions
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
can-define-rest-model — npm install can-define-rest-model · libregistry