This is the application for small school, which will store students' info in Firebase and also retrieve data from Firebase. I am using JSON Parser to parse the data and save the same in Access tables.
I am using this function in MS Access to connect to the Firebase. Please tell me if I am doing anything in an inefficient manner.
Function:
'---------------------
'#### FUcntion to make all web request and get data ####
Public Function ApiFirebaseCall(ByVal apiURL As String, _
ByVal Method As String, _
Optional ByVal apiBody As String) As String
'On Error GoTo Sub_Err
Dim reader As New XMLHTTP60
Debug.Print Method & " = " & apiURL
Debug.Print "BODY" & Nz(apiBody)
'Open URL of API
reader.Open Method, apiURL
If IsNull(apiBody) Or apiBody = "" Then
'In case of GET
reader.send
Else
'In case of POST, PATCH, DELETE
reader.send (apiBody)
End If
'Using since is was mentioned in SO. Don't know the reason why
Do Until reader.ReadyState = 4
DoEvents
Loop
If reader.Status = 200 Then
'The API was sucessful
If reader.responseText <> "null" Then
'Now check if the response contains data
ApiFirebaseCall = reader.responseText
Else
MsgBox reader.responseText
ApiFirebaseCall = "Error"
End If
Else
'The API Call was not sucessful
MsgBox reader.responseText
ApiFirebaseCall = "Error"
End If
'Debug.Print "Reader Response - " & reader.responseText
'Error Catching
Sub_Exit:
Exit Function
Sub_Err:
ApiFirebaseCall = "Error"
MsgBox Error$
Resume Sub_Exit
End Function
Example function call:
Dim apiURL, response As String
apiURL = apiBaseURL & "/d.json?auth=" & apiAuthKey
response = ApiFirebaseCall(apiURL, "GET")
'Forward processing to next function, if API Call was sucessfull
If response <> "Error" Then
JsonParser (response)
End If