Share My Creation [B4X] B4XcURL Generate B4X code from CURL command

Generate B4X code from CURL command
ex.
B4X:
    Dim CURL As B4XcURL
    CURL.Initialize
   
    Dim CurlText As String = $"curl https://api.luxand.cloud/photo/verify/1234/
      -X POST \
      -H "token: 1111111111111"  \
      -d "name=image1"  \
      -d "photo=@photo.jpg""$

    Log(CURL.GenerateCode(CurlText))
   
    Dim CurlText As String = $"curl -X POST "https://rest.nexmo.com/sms/json" \
     -d "from=15558889999" \
     -d "text=Hello from Vonage SMS API" \
     -d "to=15552279966" \
     -d "api_key=9******8" \
     -d "api_secret=N************g""$

    Log(CURL.GenerateCode(CurlText))
   
    Dim CurlText As String = $"curl -X GET "https://api.example.com/submit" \
      -d "{'key1':'value1'}" \
      -H "Content-Type: application/json""$
     
    Log(CURL.GenerateCode(CurlText))

Output:
B4X:
Public Sub POSTHttpRequest As String
        Dim Result As String
        Dim j As HttpJob
        Try
                j.Initialize("", Me)
                j.PostString("https://api.luxand.cloud/photo/verify/1234", [{"name":"image1"},{"photo":"@photo.jpg"}])
                j.GetRequest.SetHeader("token","1111111111111"
                Wait For (j) JobDone(j As HttpJob)
                If j.Success Then
                        Result = j.GetString
                End If
      Catch
                Log(LastException)
        End Try
        j.Release
        Return Result
End Sub
Public Sub POSTHttpRequest As String
        Dim Result As String
        Dim j As HttpJob
        Try
                j.Initialize("", Me)
                j.PostString("https://rest.nexmo.com/sms/json", [{"from":"15558889999"},{"text":"Hello from Vonage SMS API"},{"to":"15552279966"},{"api_key":"9******8"},{"api_secret":"N************g"}])
                Wait For (j) JobDone(j As HttpJob)
                If j.Success Then
                        Result = j.GetString
                End If
      Catch
                Log(LastException)
        End Try
        j.Release
        Return Result
End Sub
Public Sub GETHttpRequest As String
        Dim Result As String
        Dim j As HttpJob
        Try
                j.Initialize("", Me)
                j.Download2("https://api.example.com/submit", ["{'key1':'value1'}"])
                j.GetRequest.SetHeader("Content-Type","application/json"
                Wait For (j) JobDone(j As HttpJob)
                If j.Success Then
                        Result = j.GetString
                End If
      Catch
                Log(LastException)
        End Try
        j.Release
        Return Result
End Sub

Regards.
 

Sandman

Expert
Licensed User
Longtime User
Nice! Will you be sharing the source here in the forum, or do you perhaps plan to make a public webpage (like the json tool by Erel)?

I'm also curious what flags you support? For instance, would your code be able to convert this?
Bash:
curl --insecure --proxy http://192.168.1.144:8080 https://b4x.com
 

TILogistic

Expert
Licensed User
Longtime User
I created this class a few years ago and it only covers a few flags. It can be used in a web app (Jserver) since it is a single class.
 

byz

Active Member
Licensed User
It's a good idea to make a web-based conversion tool.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…