A Fluent Interface To Rapidly Interact With APIs
Create simple, resusable, and cleaner wrappers and interfaces for your API requests.
This is the first release of rapid and it is still in development. Please report any bugs to the github page.
Read the official docs at http://rapidjs.io.
Define Simple Models
var Post = new Rapid({ modelName: 'Post' });
Post.find(1).then((response) => {
});
Post.collection.findBy('category', 'featured').then((response) => {
});
Post.withParams({ limit: 20, order: 'desc' }).all().then((response) => {
});
Post.update(25, { title: 'Rapid JS Is Awesome!' })
Post.destroy(9)
Easily Customize Your API Requests
var Post = new Rapid({
modelName: 'Post',
suffixes: {
destroy: '',
update: 'save'
},
methods: {
destroy: 'delete'
},
trailingSlash: true
});
Post.update(25, { title: 'Rapid JS Is Awesome!' })
Post.destroy(9)
Create Reusable Base Models
class Base extends Rapid {
boot () {
this.baseURL = 'https://myapp.com/api';
this.config.globalParameters = { key: 'MY_API_KEY' }
}
}
var Photo = new Base({ modelName: 'Photo' });
var Gallery = new Base({ modelName: 'Gallery' });
var Tag = new Base({ modelName: 'Tag' });
Photo.find(1)
Tag.collection.findBy('color', 'red')
Gallery.id(23).get('tags', 'nature')
Write API Wrappers For Your Endpoints
class GalleryWrapper extends Rapid {
boot () {
this.baseURL = 'https://myapp.com/gallery/api';
this.modelName = 'Gallery';
}
tagSearch (query) {
return this.url('tagsearch').withParam('query', query);
}
json () {
return this.url('json');
}
}
var Gallery = new GalleryWrapper({
globalParameters: { key: 'MY_API_KEY' }
});
Gallery.tagSearch('nature').json().get().then(...);
Read the official docs at http://rapidjs.io.