django-rest-hooks icon indicating copy to clipboard operation
django-rest-hooks copied to clipboard

Hook Data Templates

Open lylepratt opened this issue 12 years ago • 3 comments

Hi!

We've been thinking about our shiny new RestHooks and thought that it would be neat if there was another column in the Hooks table that let you define an option "template" for the hook data if the hook destination needed it in an alternative format.

Very Simple example. Say I have this normal hook response defined in serialize_hook, but the data destination is expecting "phone_number" instead of "from_number":

data  = {
   'from_number': self.from_number
}

With hook templates I could change that to:

{
    'phone_number': {from_number}
}

Thoughts?

-Lyle

lylepratt avatar Nov 21 '13 17:11 lylepratt

@lylepratt I realize it has been almost two years since you have made this issue so I do apologize for getting to it so late.

Looking at the feature request, it appears that you could currently do this with Django's Template engine. This in turn could create the ideal payload based on your own criteria.

Further following separation's of concerns, I feel more inclined to say that your feature really belongs outside the scope of django-rest-hooks.

I am of course open for more discourse on this to possibly drill down the root of the feature. (i.e. what is django-rest-hooks lacking).

-Andrew

avelis avatar Sep 22 '15 20:09 avelis

Hi Andrew,

Yes its definitely possible to use Django template for the data transformation. However, the template would need to be stored with the Hook data and users would need to be able to pass in their own "data templates" when they create hooks using the Rest API. Essentially, this would require an additional model field, and if the hook model contained a valid template in that field, it should run the transformation right before sending off the hook.

lylepratt avatar Sep 23 '15 17:09 lylepratt

Seems like you can do this now with the serialize_hook method.

Ryanb58 avatar Jun 22 '18 17:06 Ryanb58