src/snorlogue/backend/backendController

Source   Edit  

Provides any and all controller procs for any HTTP request that is not of type GET.

Procs

proc createBackendController[T: Model](model: typedesc[T];
                                       urlPrefix: static string;
                                       beforeCreateAction: ActionProc[T];
                                       afterCreateAction: ActionProc[T];
                                       beforeUpdateAction: ActionProc[T];
                                       afterUpdateAction: ActionProc[T];
                                       beforeDeleteAction: ActionProc[T]): HandlerAsync

Generates a prologue controller proc for POST HTTP requests to create/update/delete entries of type model. The POST request is interpreted as a POST, PUT or DELETE request depending on the form parameter "request-type". This is a workaround over inherent HTTP form limitations, which allow only sending POST/GET requests.

After a create/update/delete, the controller forwards you to the appropriate GET controller. Requires the urlPrefix to figure out the URL to forward to.

Executes the provided ActionProcs before or after a creating/deleting/updating an entry:

  • beforeCreateAction - Gets executed before creating a model. Note that the model will not have an id yet.
  • afterCreateAction - Gets executed after creating a model
  • beforeUpdateAction - Gets executed just before updating a model. Note that the model provided is the new model that will replace the old one.
  • afterUpdateAction - Gets executed just after updating a model. Note that the model provided is the new model that has replaced the old one.
  • beforeDeleteAction - Gets executed just before deleting a model

Responds with HTTP405 if this controller gets called with any unexpected HTTP request method..

Source   Edit