B4J Question Webhook service support

avalle

Active Member
Licensed User
Longtime User
Hi, I would like to add webhook support to one of my B4J Server application.
I've not found anything about services, only client side.

Does anyone has an idea or piece of code to start from?
Can I achieve that with regular server code, or should I look at additional components?

Many thanks in advance
Andrea
 

avalle

Active Member
Licensed User
Longtime User
I mean this:
https://en.wikipedia.org/wiki/Webhook
https://zapier.com/blog/what-are-webhooks/

I did more research and essentially what I have to do in B4J is just to add the following:
B4X:
srvr.AddHandler("/webhook", "Webhook", False)
Then I create a new class module called Webhook doing things based on the specific method/headers/payload that the calling service will generate and sending a response as the calling service expects to acknowledge I have received the call.
B4X:
'Class module
Sub Class_Globals
    Private mreq As ServletRequest        'ignore
    Private mresp As ServletResponse    'ignore
End Sub

Public Sub Initialize

End Sub

Sub Handle(req As ServletRequest, resp As ServletResponse)
    mreq = req
    mresp = resp
    Dim method As String
    Dim response_type As String
    Dim clientid As String
    
    method = req.Method                    'Collect the Http method
    Log(method & " " & req.FullRequestURI)
    clientid = req.GetHeader("x-tropical-clientid")
    Log("x-tropical-clientid: " & clientid)
    response_type = req.GetParameter("response_type")
    Log("response_type: " & response_type)
    
    resp.SetHeader("x-tropical-clientid", clientid)
    resp.Write($"{"message":"Hello"}"$)
End Sub
 
Upvote 0
Top