Config 1.5: REST Verbs

If a visitor passes action=STRING in the request, Genelet will run corresponding function named STRING on component. So you may develop unlimited number of actions on the component.

If no action is passed,  a RESTful action (also called verbs) will be determined from the Request Method. This one defines the mapping:

Default_actions   {"GET":"topics", "GET_item":"edit", "PUT":"update", "POST":"insert", "DELETE":"delete"}

Here the keys are http’s Request Methods. The GET_item is a special type of GET Method with item id attached in the URL:
http://WEBSITE/HANDLER/role/mime/component/id?query…

You can change the default behavior by changing Default_actions.

The 5 verbs correspond to the following CRUD operations.

  • topics: to SELECT all items without specifying the primary key
  • edit: to get detail of one specific item by PK: WHERE id=
  • update: to update item, usually UPDATE in SQL
  • insert: to add new item, usually INSERT in SQL
  • delete: to delete item, usually DELETE in SQL

You need coding function (or object method, or subroutine) for every action. However, these five specific actions are always inherited from Genelet. Just define model parameters in component.json and it will work properly.