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:
- Method 1: Simple Function - A straightforward synchronous function that performs the GET request and returns the response as a string.
- 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).
- Method 3: Complete Class - A reusable
SupabaseClientclass with proper error handling, JSON parsing, and response validation.
Important Notes:
- Replace
YOUR_ACTUAL_ANON_KEY_HEREwith 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 )