I am doing an api for catching webhooks from a site, the website asks you to activate your webhook within the same url that will use when the webhook is called. I will have a lot of webhooks, therefore i will have a lot of repeated logic for activating the webhooks.
How could this be done using Django Rest Framework's APIView?
class MyWebhookView(APIView):
def post(self, request):
data = request.data
# repeated logic
if data.get('type') == constants.WEBHOOK_VERIFY:
hook = Hook(ID, TOKEN)
code = hook.validate(data.get('hook_id'), data.get('code'))
return Response({'code': code})
# custom logic