Minimal code for CRUD operations on REST APIs with JavaScript
CRUD.js is an easy way to consume RESTful APIs in JavaScript.
You can use CRUD.js to make it done complete CRUD operations on a REST service with a minimal number of code anywhere you can use JavaScript, very specially on single page web applications.
- Call Rest API CRUD with minimum code.
- Ability to use ui templates of your own.
- If no templates are used fall back to default html template.
Below is quick example how to use CRUD.js:
$(document).ready(function(){
$.CRUD.path = "http://www.example.com/api";
var Book= new $.CRUD("book");
Book.list();
});
This could be the only JavaScript codes you have to write for the whole application.
$.CRUD.path // root URL for REST API
$.CRUD.container // where the HTML content should be embeded; default is 'container'
$.CRUD.resources // root folder for external templates; default is 'res'
In this example, the CRUD.path
config property takes one parameter to the ROOT URL of your REST API.
The constructor is passed the Table you want to operate on.
When we invoke list method on the object all the CRUD operations on this Table.
<table>
<a href="#!add" data-action="add" >Add</a>
{{#Books}}
<tr>
<td>
{{Id}}
</td>
<td>
{{Title}}
</td>
<td>
<a href="#!view" data-action="view" data-id="{{Id}}">View</a>
<a href="#!edit" data-action="edit" data-id="{{Id}}">Edit</a>
<a href="#!delete" data-action="delete" data-id="{{Id}}">Delete</a>
</td>
</tr>
{{/Books}}
</table>
In here we have used mustache.js as the templating framework.
data-action // CRUD operations like view, update, delete,..
data-id // Unique identifier for the record
CRUD.js wouldn't kick ass if it weren't for these fine souls:
Git: tidalbobo
E-mail: [email protected]
LinkedIn: gayan-kulatilleke
Git: weliwita
E-mail: [email protected]
LinkedIn: rasika-weliwita
Git: agentmilindu
Email: [email protected]
LinkedIn: Milindu Sanoj Kumarage
Twitter: @agentmilindu
Git: lasanthasuresh
Email: [email protected]
Linkedin: suresh-lasantha
Twitter: @lasanthasuresh
Git: dhammika-marasinghe
E-mail: [email protected]
LinkedIn: dhammikamarasinghe
twitter: @Dhammika
Git: nmmanas
E-mail: [email protected]
LinkedIn: manasnajmuddeen
Twitter: @nmmanas