Web Hooks is an open initiative to standardize event notifications between web services by subscribing to URLs.
Django WebHooks makes it easy to integrate WebHooks into your Django Project.
-
Download the code from GitHub:
git clone git://github.com/johnboxall/django-webhooks.git webhooks
-
Edit
settings.py
and addwebhooks
to yourINSTALLED_APPS
:# settings.py ... INSTALLED_APPS = (... 'webhooks', ...)
-
Register webhooks for models -
admin.py
is a good place:# admin.py from webhooks import webhooks webhooks.register(MyModel, ["fields", "to", "serialize"])
-
Create Listeners for the webhook. For example to create a Listener that will be messaged whenever a
User
instance withusername="john"
is saved:from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType from webhooks.models import Listener user_type = ContentType.objects.get(app_label="auth", model="user") john = User.objects.get(username="john") Listener.create(obj_type=user_type, obj_property="username", obj_value="john", url="http://where.john/is/listening/", owner=john)
-
Profit.
-
Django:
# views.py import simplejson def listener(request): json = request.raw_post_data webhook = simplejson.loads(json)
-
PHP:
<?php // http://ca3.php.net/manual/en/reserved.variables.httprawpostdata.php // http://ca3.php.net/manual/en/wrappers.php.php $json = file_get_contents('php://input'); // http://ca3.php.net/manual/en/function.json-decode.php var_dump(json_decode($json, true)); ?>
- HTTP POST request / raw_post_data
- Creating a listener ...
- ...
- Code in
webhooks.models.Message
should be moved intowebhooks.helpers
so it can be subclassed / overridden more easily. - Add HMAC authorization headers to all Webhooks messages ([http://code.google.com/p/support/wiki/PostCommitWebHooks](see Google Code implementation)
- Add verify view for (think PayPal IPN)
- http://blog.webhooks.org/
- http://blogrium.com/2006/12/27/automator-for-the-web/
- http://blogrium.com/2006/11/27/lets-make-seeking-bliss-easier/
- http://blogrium.com/?p=70
- http://www.slideshare.net/progrium/web-hooks Web-Hooks by blogrium.com / superhappydevhouse
- http://groups.google.com/group/webhooks/ webhooks google group
- http://code.google.com/p/support/wiki/PostCommitWebHooks
- http://www.slideshare.net/progrium/web-hooks-and-the-programmable-world-of-tomorrow-presentation
- http://github.com/guides/post-receive-hooks