B4J Library [Web] Sithaso SDUIFetch - A Non Head Cracking Approach to BANanoFetch

Hi Fam

SDUIFetch is internal to SithasoDaisy. Its aim is to make it easier to use BANanoFetch as its a wrap on top of BANanoFetch, to make it easier to use. Well, after so many times of forgetting how BANanoFetch works, I opted for an easier approach.

Imagine.

B4X:
''execute the fetch
Dim j As SDUIFetch
'initialize the fetch with the base url
j.Initialize("https://api.funtranslations.com/translate/minion.json")
'add a parameters
j.AddParameter("text", txtMessage.value)
'set content type
j.SetContentTypeApplicationJSON
'add header
j.AddHeader("X-Funtranslations-Api-Secret", "")
j.NoCache = True
'execute the post
BANano.Await(J.PostWait)
If j.Success Then
    Dim Response As Map = j.response
    If Response.ContainsKey("contents") Then
        Dim minionTaal As String = j.GetRecursive(Response, "contents.translated")
        txtConvert.Value = minionTaal
    End If
Else  
    txtConvert.Value = j.ErrorMessage
End If

Internally this uses BANanoFetch but personally for me in a more easier apprieach.
 

Attachments

  • SDUIFetch.bas
    14.6 KB · Views: 19
Last edited:

Mashiane

Expert
Licensed User
Longtime User
Passing Files

B4X:
fetch.Initialize(???)
    fetch.NewFormData
    fetch.AddFormData("file", fileObj)
    fetch.AddFormData("fileName", fileNameChat)
    BANAno.Await(fetch.PostWait)
    If fetch.Success Then
        Response = fetch.response
        Return Response
    Else
        Log(fetch.ErrorMessage)
        Return Response
    End If
 

Mashiane

Expert
Licensed User
Longtime User
Executing a Get

B4X:
Sub GetStateInstance As String
    fetch.Initialize(?)
    fetch.SetContentTypeApplicationJSON
    BANAno.Await(fetch.GetWait)
    If fetch.Success Then
        Dim Response As Map = fetch.response
        If Response.ContainsKey("stateInstance") Then
            Dim res As String = Response.Get("stateInstance")
            Return res
        Else
            Return ""    
        End If
    Else
        Log(fetch.ErrorMessage)
        Return ""
    End If
End Sub
 

Mashiane

Expert
Licensed User
Longtime User
Executing a Delete

B4X:
fetch.Initialize($"${sapiUrl}/waInstance${thisIdInstance}/deleteNotification/${thisApiTokenInstance}/${receiptId}"$)
    fetch.SetContentTypeApplicationJSON
    BANAno.Await(fetch.DeleteWait)
    If fetch.Success Then
        Dim Response As Map = fetch.Response
        Dim bresult As Boolean = CBool(Response.Get("result"))
        Return bresult
    Else
        Log(fetch.ErrorMessage)
        Return False
    End If
 
Top