CRUD API V3

Summary

Create a CRUD resource complete with HTTP routes and state persistance.

Using the function is as easy as:

  1. importing it,
  2. specifying a name for the resource (in Settings -> Parameters), and
  3. emit a response.

In Settings -> Parameters additional settings can be specified. You may specify a schema that the resource should conform to, which CRUD actions to enable, and opt in to use LoLo authentication/authorization. Please consult the Settings -> Parameters for documentation on each setting.

Ports

A action where no error (auth, validation, etc) produces an event that is routed to the out port.

Input/Output Format

The produced event is an object. The object has properties associated with the HTTP request that triggered the action. (method, path, params, query, body and headers.)

All events also has the property crud which is an object that has two properties: action and resource. action is one of 'read', 'list', 'update', 'patch', 'create', or 'delete'. resource is a string hand holds the resource name specified in Settings -> Parameters.

All events also holds a pre-built HTTP response in the response property, with a status property representing a suggested HTTP status and a body property representing a suggested HTTP response body. The suggestions are informed by the action performed.

If authentication is specified to be used in Settings -> Parameters, then a session property is also set on the event. Please consult LoLo API Auth for details on the format of this property.

If a specific resource is accessed by it's ID, then the event will have a resource and a resourceKey property. The resourceKey property is a string that is used to access the resource in LoLo state. The resource property holds the accessed resource. This property is also present in case of a create action.

When a list action is performed, the items property is set on the event. This property is an array of all resources.

Events

This function listen for events named response. Please consult the documentation for HTTP Trigger for more details on this event.