How to use the Salmon CRUD API

Please make sure you have read and understand the Salmon Data model prior addressing the CRUD operations.

CRUD stands for Create/Read/Update/Delete and refers to operations you wish to do with data. For example, adding a product to your online shop (Create), listing products available for sale (Read), modify some order information (Update), remove some entry (Delete).

The primary Salmon server-side API calls for data management are:

- e2cCreate
- e2cDelete
- e2cList
- e2cGet
- e2cUpdate

These are generic calls, and should match all possibilities. They will handle your CRUD requests along necessary security checks and data store logic. The subsequent JSON returned by the server will contain all the data your required (for Read) or a status code (for Create/Update/Delete).

For debugging purposes, you may use direct URL access to the API to check what is returned. Otherwise, your client side javascript should leverage on E2C.js (helpers and behaviors) to prepare the request and have the data populated into your web page.

Create

Create operations are made by calling the e2cCreate end-point.

Let say, to keep it simple, that you have a DB table 'books' with columns bookID|title|price|ownerID|private_info.

Your request would be: http://yourdomain/e2cCreate?t=books&e2ctitle=sometitle&e2cprice=10 .

You only need to specify the DB table name and the columns that you want to enter some data at row creation time. Other columns, such as auto-increment (here bookID), will be handled by Salmon.

Data will be created with data ownership set to the account the user is logged in at creation time. The fields to use as index (here bookID) and to check data ownership (here ownerID) must be set into the Salmon data firewall.

While subject to future change, the parameter names which represent data tables (here price and title) must be prefixed with 'e2c'.


Read

While the CRUD API has 2 end-points for Read operations, namely e2cList and e2cGet, as of Salmon V4 it is always preferable to use e2cList unless specifically advised so by the documentation.

With the same DB table as prior above, your request would be: http://yourdomain/e2cList?t=books

Note that you may make more specific data requests and that you could use the Salmon data firewall settings to not return the 'private_info' column data.


Update

Updates are made by calling the e2cUpdate end-point.

Let say we use the same DB table as above and wish to update the price and the title of the book with bookID 42. Your request would be: http://yourdomain/e2cUpdate?t=books&r=42&e2cprice=20.5&e2ctitle=thegreensky

Salmon will internally check if you have ownership on this data. If not the operation will be discarded. The fields to use as index (here bookID, passed as 'r' request parameter) and to check data ownership (here ownerID) must be set into the Salmon data firewall.

While subject to future change, the parameter names which represent data tables (here price and title) must be prefixed with 'e2c'.


Delete

Deletes are made by calling the e2cDelete end-point.

Using the same DB structure example as above, let say we want to remove the entry for the book with bookID 42. Your request would be: http://yourdomain/e2cDelete?t=books&r=42

Salmon will internally check if you have ownership on this data. If not the operation will be discarded. The fields to use as index (here bookID, passed as 'r' request parameter) and to check data ownership (here ownerID) must be set into the Salmon data firewall.