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.


'#### 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
    '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

    If reader.Status = 200 Then
    'The API was sucessful
        If reader.responseText <> "null" Then
        'Now check if the response contains data
            ApiFirebaseCall = reader.responseText
            MsgBox reader.responseText
            ApiFirebaseCall = "Error"
        End If
    'The API Call was not sucessful
        MsgBox reader.responseText
        ApiFirebaseCall = "Error"
    End If

    'Debug.Print "Reader Response - " & reader.responseText

'Error Catching
    Exit Function
    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
  • \$\begingroup\$ Welcome to Code Review! I hope you get some great answers. \$\endgroup\$ – Phrancis Aug 10 '16 at 6:23
  • \$\begingroup\$ Without knowing all the details, I can't help wondering why you are using REST to retrieve data when you would have much easier retrieving data using a ODBC connection, which FireBird supports, and would not require you to parse JSON. \$\endgroup\$ – this Sep 21 '17 at 8:56
  • \$\begingroup\$ @this. I am taking about FireBase, not FireBird. \$\endgroup\$ – Adarsh Sep 23 '17 at 11:27
  • \$\begingroup\$ What is your JsonParser function? \$\endgroup\$ – Raystafarian Mar 15 '18 at 23:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.