can-connect client for Flask-Restless
npm install can-restless
flask-restless
#install flask-restless from github:
virtualenv env
source env/bin/activate
pip install -e git://github.com/jfinkels/flask-restless.git#egg=flask-restless
#install can-restless
npm install can-restless --save
npm run export
`
AMD
`javascript
require(['can-restless/dist/amd/index'], function(Factory){
var Task = Factory(/ ... /);
});
`
Require JS
`javascript
var Factory = require('can-restless/dist/cjs/index');
var Task = Factory(/ .... /);
`
StealJS - ES6 Style Example
`javascript
import Factory from 'can-restless';
import CanMap from 'can/map/';
let TaskMap = CanMap.extend({
name: 'My Task',
description: 'More details about the task'
is_complete: false,
});
let Task = Factory({
map: TaskMap,
//this is the default id property
//idProp: 'id',
name: 'task',
url: '/api/tasks'
});
//fetch the list with no parameters
let deferred = Task.getList({});
//fetch the list with sorting
deferred = Task.getList({
sort: {
type: 'asc',
fieldName: 'description'
}
});
//fetch the list with a filter
deferred = Task.getList({
filters: [{
name: 'description',
operator: 'like',
value: '%details%'
}]
});
//fetch one item by id
deferred = Task.get({
id: 1
});
`
Running the tests
Set up flask restless:
`
cd test/demo
virtualenv env
source env/bin/activate
pip install -r pip_require.txt
python run.py
`
Once the development server is running, run the tests either in a browser at index.html or by running
`
npm run test
`
Limitations
Filtering:
Currently the only filter syntax supported is the array type with name, op, and val. Each filter in the array will be "and". Or is not currently implemented. For example:
`
deferred = Task.getList({
filters: [{
name: 'description',
operator: 'like',
value: '%details%'
}, {
name: 'birth_date',
operator: 'after',
value: '10/5/2005'
}]
});
``