扫一扫分享
rapid.js为您的API请求创建简单,可重用,更简洁的封装,定义自定义路由等等。
安装
yarn add rapid.js
npm i -S rapid.js
npm install --save rapid.js
定义简单模型
const post = new Rapid({ modelName: 'Post' });
post.find(1).then((response) => {
// GET => /api/post/1
});
post.collection.findBy('category', 'featured').then((response) => {
// GET => /api/posts/category/featured
});
post.withParams({ limit: 20, order: 'desc' }).all().then((response) => {
// GET => /api/posts?limit=20&order=desc
});
post.update(25, { title: 'Rapid JS Is Awesome!' })
// POST => /api/posts/25/update
post.destroy(9)
// POST => /api/posts/9/destroy
post.restore(9)
// POST => /api/posts/9/restore
轻松自定义您的API请求
const post = new Rapid({
modelName: 'Post',
suffixes: {
destroy: '',
update: 'save'
},
methods: {
destroy: 'delete'
},
trailingSlash: true
});
post.update(25, { title: 'Rapid JS Is Awesome!' })
// POST => /api/posts/25/save/
post.destroy(9)
// DELETE => /api/posts/9/
手机预览