11
\$\begingroup\$

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
Tolani
2,5017 gold badges31 silver badges49 bronze badges
asked Aug 10, 2016 at 5:19
\$\endgroup\$
4
  • \$\begingroup\$ Welcome to Code Review! I hope you get some great answers. \$\endgroup\$ Commented Aug 10, 2016 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\$ Commented Sep 21, 2017 at 8:56
  • \$\begingroup\$ @this. I am taking about FireBase, not FireBird. \$\endgroup\$ Commented Sep 23, 2017 at 11:27
  • \$\begingroup\$ What is your JsonParser function? \$\endgroup\$ Commented Mar 15, 2018 at 23:47

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.