Cubicweb WSME¶
Summary¶
Easily build a webservice API on top of a cubic web database.
Once activated, the cube provides new controllers (their regid is webservices) which respond on the rest path of entities, if the requests matches one of the following condition:
- Content-Type == ‘application/json’
- Accept == ‘application/json’
The following API is automatically provided for all the entities:
HTTP | action |
GET /etype?filter=xxx | return a list of entities matching the filter |
POST /etype | create a new entity |
GET /etype/1234 | return a particular entity |
PUT /etype/1234 | update an entity |
DELETE /etype/1234 | delete an entity |
Getting Started¶
Install the cube:
pip install cubicweb-wsme
Activate the cube on your instance:
add_cube("wsme")
Your instance now provides webservices
Call your APIs, for example from javascript (using jQuery):
$.ajax({ url: 'http://localhost:8080/cwuser', dataType: 'json', data: { // get users which name starts with "dupon" filter: JSON.stringify({ 'surname': { '$ilike': 'dupon%' } }, // retrieve the user groups references fetch: [ 'in_group' ], // order by login DESC orderby: '-login' }, traditional: true, success: function (data) { // data is a list looking like this: // [{eid: 000, login: "xx", ...., in_group: [{eid: 0, modification_date: 'xxx'}, {eid: ...}]}] console.log("Got", data, "!"); } });