Recent

Author Topic: restbridgeclient doesn't do 'GET'  (Read 813 times)

rca

  • Jr. Member
  • **
  • Posts: 84
restbridgeclient doesn't do 'GET'
« on: June 29, 2024, 07:54:21 am »
I am working with example restbridgeclient (pasjs demo) and restserver (Lazarus demo) from sqldbrest.

When using jsonclient (Lazarus demo) it works OK and the server shows:
Code: Bash  [Select][+][-]
  1. [Resource] (User: ?) Resource: metadata; Operation: GET
  2. [Connection] (User: ?) Using connection to Host: localhost; Database: expensetracker
  3. [Authentication] (User: me) Authenticated user: me
  4. [Result] (User: me) Resource: metadata; Operation: GET; Status: 200; Text: OK

However, when using restbridgeclient example (pasjs demo), it doesn't work and the server shows:
Code: Bash  [Select][+][-]
  1. [Result] (User: ?) Resource: metadata; Operation: OPTIONS; Status: 403; Text: FORBIDDEN

The difference is in the Operation, it should be 'GET', but it sends 'OPTIONS'.

In the unit sqldbrestdataset, there is the "constructor TServiceRequest.Create", if I comment the following line of code
Code: Pascal  [Select][+][-]
  1. FXHR.setRequestHeader('Authorization', 'Basic '+window.btoa(aUserName+':'+aPassword));
it sends the 'GET' method, but obviously it would not be authenticated and still does not work.

Please can you help me solve it?

Thank you


rca

  • Jr. Member
  • **
  • Posts: 84
[SOLVED] restbridgeclient doesn't do 'GET'
« Reply #1 on: July 01, 2024, 03:57:23 pm »
After finding and reading some information:
https://stackoverflow.com/questions/63752007/axios-request-method-changes-to-options-instead-of-get
https://stackoverflow.com/questions/21783079/ajax-in-chrome-sending-options-instead-of-get-post-put-delete
https://stackoverflow.com/questions/29954037/why-is-an-options-request-sent-and-can-i-disable-it

In short, it not only happens with the 'GET' method, it will also happen with 'POST', 'PUT' or 'DELETE'.

"OPTIONS request is part of the so-called preflight request which is needed to figure out the CORS headers to know what needs/is allowed to be sent to the server with the actual request."

More details about "Cross-Origin Resource Sharing (CORS)"
https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
"CORS preflight"
https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request

So the solution is on the server side (restserver Lazarus demo), within Dispatcher options, enable "rdoHandleCORS" (Handle CORS requests) and that's it!

Enjoy!

 

TinyPortal © 2005-2018