Claude to write MBScurl API to supabase

since we don’t see much claude generated code, i’ve done some testing, i will publish examples on git
xojo methods parsing json into dictionnary or object
xojo example reading TSV file than saving to with fields name as first row in SQLite
this is crazy it all worked easily, crazy sh1t !! it write better xojo code than me !,
using opus 4.1, burns more credit but worth it !

i’m now asking it to write urlconnection stuff

is there any curlmbs gurus to tell me if the has any chances for this to work ?
it’s for writing to supabase API using curl

// Xojo API 2 code using CurlMBS to fetch data from Supabase

key Features:

  1. Method 1: Simple Function - A straightforward synchronous function that performs the GET request and returns the response as a string.
  2. Method 2: Async Approach - Shows how to set up an asynchronous request using CURLSMultiMBS (you’d need to implement a timer to check for completion).
  3. Method 3: Complete Class - A reusable SupabaseClient class with proper error handling, JSON parsing, and response validation.

Important Notes:

  • Replace YOUR_ACTUAL_ANON_KEY_HERE with your actual Supabase anonymous key
  • The code includes proper header configuration matching your curl command
  • Error handling for both CURL errors and HTTP response codes
  • JSON parsing capabilities for processing the response
  • Additional helper method for POST requests if needed

// Method 1: Using CURLSMBS (synchronous version)
Private Function FetchSupabaseEvents() As String
  // Create a new CURL session
  Var curl As New CURLSMBS
  
  // Your Supabase credentials
  Var SUPABASE_CLIENT_ANON_KEY As String = "YOUR_ACTUAL_ANON_KEY_HERE"
  Var url As String = "https://sctxaurqodgkxqkvubpa.supabase.co/rest/v1/events?select=*"
  
  // Set the URL
  curl.OptionURL = url
  
  // Set the headers
  Var headers() As String
  headers.Add("apikey: " + SUPABASE_CLIENT_ANON_KEY)
  headers.Add("Authorization: Bearer " + SUPABASE_CLIENT_ANON_KEY)
  
  // Apply headers to the curl request
  curl.SetOptionHTTPHeader(headers)
  
  // Optional: Set timeout
  curl.OptionTimeout = 30
  
  // Optional: Enable verbose output for debugging
  // curl.OptionVerbose = True
  
  // Perform the request
  Var result As Integer = curl.Perform
  
  // Check if the request was successful
  If result = 0 Then
    // Success - return the response
    Var response As String = curl.OutputData
    
    // Optional: Check HTTP response code
    Var httpCode As Integer = curl.GetInfoResponseCode
    System.DebugLog("HTTP Response Code: " + httpCode.ToString)
    
    Return response
  Else
    // Error occurred
    System.DebugLog("CURL Error: " + curl.LastErrorMessage)
    System.DebugLog("Error Code: " + result.ToString)
    Return ""
  End If
  
End Function

// Method 2: Using CURLSMultiMBS (for non-blocking/asynchronous operations)
Private Sub FetchSupabaseEventsAsync()
  // Create multi handle for managing multiple requests
  Var multi As New CURLSMultiMBS
  
  // Create a CURL handle
  Var curl As New CURLSMBS
  
  // Your Supabase credentials
  Var SUPABASE_CLIENT_ANON_KEY As String = "YOUR_ACTUAL_ANON_KEY_HERE"
  Var url As String = "https://sctxaurqodgkxqkvubpa.supabase.co/rest/v1/events?select=*"
  
  // Set the URL
  curl.OptionURL = url
  
  // Set the headers
  Var headers() As String
  headers.Add("apikey: " + SUPABASE_CLIENT_ANON_KEY)
  headers.Add("Authorization: Bearer " + SUPABASE_CLIENT_ANON_KEY)
  
  // Apply headers
  curl.SetOptionHTTPHeader(headers)
  
  // Store reference to curl for later use
  curl.Tag = "supabase_events"
  
  // Add to multi handle
  multi.AddCURL(curl)
  
  // Start performing the request
  // You'll need to call multi.PerformOnce in a timer or loop
  // to check for completion
  
End Sub

// Method 3: Complete class implementation with error handling
Public Class SupabaseClient
  
  Private mAPIKey As String
  Private mBaseURL As String
  
  Public Sub Constructor(baseURL As String, apiKey As String)
    mBaseURL = baseURL
    mAPIKey = apiKey
  End Sub
  
  Public Function GetEvents() As Dictionary
    Var curl As New CURLSMBS
    Var url As String = mBaseURL + "/rest/v1/events?select=*"
    
    // Configure the request
    curl.OptionURL = url
    
    // Set headers
    Var headers() As String
    headers.Add("apikey: " + mAPIKey)
    headers.Add("Authorization: Bearer " + mAPIKey)
    headers.Add("Content-Type: application/json")
    headers.Add("Prefer: return=representation")
    
    curl.SetOptionHTTPHeader(headers)
    
    // Set additional options
    curl.OptionTimeout = 30
    curl.OptionFollowLocation = True
    curl.OptionSSLVerifyPeer = 1
    curl.OptionSSLVerifyHost = 2
    
    // Perform the request
    Var result As Integer = curl.Perform
    
    If result = 0 Then
      Var httpCode As Integer = curl.GetInfoResponseCode
      Var responseData As String = curl.OutputData
      
      If httpCode >= 200 And httpCode < 300 Then
        // Success - parse JSON response
        Try
          Var json As New JSONItem(responseData)
          
          // Convert to Dictionary for easier handling
          Var response As New Dictionary
          response.Value("success") = True
          response.Value("data") = json
          response.Value("httpCode") = httpCode
          
          Return response
        Catch e As JSONException
          // JSON parsing error
          Var errorResponse As New Dictionary
          errorResponse.Value("success") = False
          errorResponse.Value("error") = "JSON parsing failed: " + e.Message
          errorResponse.Value("rawResponse") = responseData
          Return errorResponse
        End Try
      Else
        // HTTP error
        Var errorResponse As New Dictionary
        errorResponse.Value("success") = False
        errorResponse.Value("httpCode") = httpCode
        errorResponse.Value("error") = "HTTP Error: " + httpCode.ToString
        errorResponse.Value("response") = responseData
        Return errorResponse
      End If
    Else
      // CURL error
      Var errorResponse As New Dictionary
      errorResponse.Value("success") = False
      errorResponse.Value("error") = "CURL Error: " + curl.LastErrorMessage
      errorResponse.Value("errorCode") = result
      Return errorResponse
    End If
  End Function
  
End Class

// Usage example:
Private Sub ExampleUsage()
  // Method 1: Simple function call
  Var response As String = FetchSupabaseEvents()
  If response <> "" Then
    System.DebugLog("Response: " + response)
    
    // Parse JSON if needed
    Try
      Var json As New JSONItem(response)
      // Process your JSON data here
    Catch e As JSONException
      System.DebugLog("JSON Error: " + e.Message)
    End Try
  End If
  
  // Method 3: Using the class
  Var client As New SupabaseClient("https://sctxaurqodgkxqkvubpa.supabase.co", "YOUR_ACTUAL_ANON_KEY_HERE")
  Var result As Dictionary = client.GetEvents()
  
  If result.Value("success") = True Then
    Var data As JSONItem = result.Value("data")
    // Process your data
    System.DebugLog("Successfully fetched events")
  Else
    Var errorMsg As String = result.Value("error")
    System.DebugLog("Error: " + errorMsg)
  End If
End Sub

// Additional helper method for POST requests
Private Function PostToSupabase(endpoint As String, jsonData As String, apiKey As String) As String
  Var curl As New CURLSMBS
  Var url As String = "https://sctxaurqodgkxqkvubpa.supabase.co/rest/v1/" + endpoint
  
  curl.OptionURL = url
  curl.OptionPost = True
  curl.OptionPostFields = jsonData
  
  // Set headers
  Var headers() As String
  headers.Add("apikey: " + apiKey)
  headers.Add("Authorization: Bearer " + apiKey)
  headers.Add("Content-Type: application/json")
  headers.Add("Prefer: return=representation")
  
  curl.SetOptionHTTPHeader(headers)
  
  Var result As Integer = curl.Perform
  
  If result = 0 Then
    Return curl.OutputData
  Else
    Return ""
  End If
End Function

to insert a row

curl -X POST 'https://sctxaurqodgkxqkvubpa.supabase.co/rest/v1/events' \
-H "apikey: SUPABASE_CLIENT_ANON_KEY" \
-H "Authorization: Bearer SUPABASE_CLIENT_ANON_KEY" \
-H "Content-Type: application/json" \
-H "Prefer: return=minimal" \
-d '{ "some_column": "someValue", "other_column": "otherValue" }'
          

thanks , might it be unsable ? or not worth trying ?, i don’t want to try, opus 4.1 burn my credit faster i have to wait 24h, but worth it !

ii’s over, i’m done writing code, writing code is for noobs ! ( i know i’m going to triger some people here lol )

Are you honestly asking for people to assess this code rather than you try it ? Really ?

1 Like

yes, really ,sorry:)
one would say in a blink that if this could work or not, i’ve tried jsonMBS kinda work but takes some fixing, sorry i don’t have much time, i wish i did

and anyway making a curl wrapper to Supabase API would be usefull, Supabase is gaining traction.

anyway i already have 5-6 working xojo project to test stuff ! all worked ! crazy !, i will put it on git, as boilerplate to data manipulation, i didn’t even read the code, jump to next idea,

an i’m laughing inside, i won’t get advice from people i’ve trigered, so i’ll end up next week trying myself
SO GREAT NEWS, ! CLAUDE CAN WRITE PERFECTLY WORKING CODE ! :heart_eyes::

(PS and i think AI makes DBKit obsolete…)

You’re not getting advice because trying it yourself is what you should have done in the first place! You don’t want to write your own code, understand what it’s doing, or even test it. That doesn’t exactly inspire people to help.

I’ve got problems with this code, but I’ll point out some low hanging fruit:

Why would any API need the same value twice?

2 Likes

You don’t need the timer to check regularly. You can just wait for the TransferFinished event.

See

Easier multi transfer for our Xojo CURL Plugin

yes exactly :slight_smile:

i told claude to tranlate this in xojo code

bash:
curl 'https://sctxaurqodgkxqkvubpa.supabase.co/rest/v1/events?select=*' \
-H "apikey: SUPABASE_CLIENT_ANON_KEY" \
-H "Authorization: Bearer SUPABASE_CLIENT_ANON_KEY"
          

i will dig the supabase doc

oki thanks