Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2022-10

demorestbridge

10 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

duilio foschi

I am trying to use the demo that I find in directory

C:\lazarus\fpc\3.2.2\source\packages\fcl-web\examples\restbridge

Following the instructions in file readme.txt,

1. I created a firebird database (test.fdb)
2. I run expenses-fb.sql to create the db structure
3. I run expenses-data.sql to insert some data in the tables

Now I read:

<<
You must edit the program to provide the correct database credentials: look for the ExposeDatabase() call, and edit the username/password. You must also change the name and location of the database

>
so I changed the original line
FDisp.ExposeDatabase(TPQConnectionDef.TypeName,'localhost','expensetracker','You','YourSecret',Nil,[foFilter,foInInsert,foInUpdate,foOrderByDesc]);
into
FDisp.ExposeDatabase(TPQConnectionDef.TypeName,'localhost','c:\....\test.fdb','sysadm','masterkey',Nil,[foFilter,foInInsert,foInUpdate,foOrderByDesc]);

(where the database path is of course
C:\lazarus\fpc\3.2.2\source\packages\fcl-web\examples\restbridge\test.fdb )

However when I compile and run the demo, I get the following error message: "Can not load PostgreSQL client library "libpq.dll". Check your installation"

I noticed that a library of name libpq.dll is inside the demo directory. This library was 32 bits, but I compile the downloaded the 64bit library but still no joy (same error).

A solution is suggested here
https://forum.lazarus.freepascal.org/index.php?topic=43476.0 with several DLLs copied into the working directory but...

who wants Postgres? I only work with Firebird. How do I change the code so that only Firebird databases are handled (and no Postgres DLL is needed)?

Also: how does the bridge know about the database type one wants to use?

I could find no explanation re this question in pages https://wiki.freepascal.org/SQLDBRestBridge

Any help?

Thank you

Peppe

Reply by email

zeljko
to duilio foschi
duilio foschi wrote 23 lines
I am trying to use the demo that I find in directory C:\lazarus\fpc\3.2.2\source\packages\fcl-web\examples\restbridge Following the instructions in file readme.txt, 1. I created a firebird database (test.fdb) 2. I run expenses-fb.sql to create the db structure 3. I run expenses-data.sql to insert some data in the tables Now I read: << You must edit the program to provide the correct database credentials: look for the ExposeDatabase() call, and edit the username/password. You must also change the name and location of the database >> so I changed the original line FDisp.ExposeDatabase(TPQConnectionDef.TypeName,'localhost','expensetracker','You','YourSecret',Nil,[foFilter,foInInsert,foInUpdate,foOrderByDesc]); into FDisp.ExposeDatabase(TPQConnectionDef.TypeName,'localhost','c:\....\test.fdb','sysadm','masterkey',Nil,[foFilter,foInInsert,foInUpdate,foOrderByDesc]);

TPQConnection is postgresql thing only, you must use TIBConnection for firebird.

zeljko

Reply by email

duilio foschi
to zeljko

following the suggestions offered by zeljiko (thank you, zeljko), I was able to compile and successfully run
demorestbridge.exe

Albeit no message is displayed when the EXE starts, I can see that the application is alive and answering requests at port 3000 (I use command >netstat -bano for this).

The next step I'd like to reach is to run a client demo that will communicate with the server above.

Demo bufclient compiles successfully

At start time, I need to insert data into 3 boxes:

1. URL
2. username
3. password

#2 and #3 are no problem, of course.

#1 puzzles me.

The box has the following string preset
http://localhost:3000/

To my poor knwoledge, http requires a web server and I have no web server running in my PC with windows 7.

Is there any way to do a quick test of demorestbridge.exe without installing a web server?

Probably a stupid question...

Thank you

Peppe

Reply by email

Michael Van Canneyt
to duilio foschi: following the suggestions offered by zeljiko (thank you, zeljko), I was able to compile…
duilio foschi wrote 31 lines
following the suggestions offered by zeljiko (thank you, zeljko), I was able to compile and successfully run demorestbridge.exe Albeit no message is displayed when the EXE starts, I can see that the application is alive and answering requests at port 3000 (I use command >netstat -bano for this). The next step I'd like to reach is to run a client demo that will communicate with the server above. Demo bufclient compiles successfully At start time, I need to insert data into 3 boxes: 1. URL 2. username 3. password #2 and #3 are no problem, of course. #1 puzzles me. The box has the following string preset http://localhost:3000/ To my poor knwoledge, http requires a web server and I have no web server running in my PC with windows 7. Is there any way to do a quick test of demorestbridge.exe without installing a web server?

You don't need a webserver if you are using the demorestbridge.

demorestbridge.exe itself acts as a webserver, it listens on port 3000.

You can test this by typing the following in a browser address bar:

http://localhost:3000/REST/metadata

and you should get the metadata from the REST service. (you may need to provide the username and password you configured in the rest bridge)

If that works, then in the bufclient demo, enter the URL

http://localhost:3000/REST/

And push 'Get resource list' button to see a list of resources.

Michael.

Reply by email

duilio foschi
to Michael Van Canneyt
>

You can test this by typing the following in a browser address bar:

http://localhost:3000/REST/metadata
and you should get the metadata from the REST service. <<

I tried this but I dont get the metadata as expected.

Instead, the browser displays the following message in json format

{
"error" : {
"code" : 404,
"message" : "NOT FOUND"
}
}

>

(you may need to provide the username and password you configured in the rest bridge)
<<

could you please expand on this? How do I provide username/password from the browser?

When we talk about username/password do we mean one of the rows of table USERS?

I run bufclient but the answer is always the same: 404 NOT FOUND

What am I missing?

Thank you

Peppe

AM Michael Van Canneyt wrote 61 lines
On Tue, 25 Oct 2022, duilio foschi via lazarus wrote: > following the suggestions offered by zeljiko (thank you, zeljko), I > was able to compile and successfully run > demorestbridge.exe > > Albeit no message is displayed when the EXE starts, I can see that the > application is alive and answering requests at port 3000 (I use > command >netstat -bano for this). > > The next step I'd like to reach is to run a client demo that will > communicate with the server above. > > Demo bufclient compiles successfully > > At start time, I need to insert data into 3 boxes: > > 1. URL > 2. username > 3. password > > #2 and #3 are no problem, of course. > > #1 puzzles me. > > The box has the following string preset > http://localhost:3000/ > > To my poor knwoledge, http requires a web server and I have no web > server running in my PC with windows 7. > > Is there any way to do a quick test of demorestbridge.exe without > installing a web server? You don't need a webserver if you are using the demorestbridge. demorestbridge.exe itself acts as a webserver, it listens on port 3000. You can test this by typing the following in a browser address bar: http://localhost:3000/REST/metadata and you should get the metadata from the REST service. (you may need to provide the username and password you configured in the rest bridge) If that works, then in the bufclient demo, enter the URL http://localhost:3000/REST/ And push 'Get resource list' button to see a list of resources. Michael. -- _______________________________________________ lazarus mailing list https://lists.lazarus-ide.org/listinfo/lazarus

Reply by email

duilio foschi
to duilio foschi

I tried to run demorestbridge inside Lazarus in debug mode.

When the web browser points to
http://localhost:3000/REST/metadata

the debugger shows an error message that says:

'project SQLDB REST bridge raised an exception of class 'EHTTP' with message: No REQUEST_METHOD passed from server.. At address 10009D512'

Any idea what this could mean?

Thank you

Peppe

PM duilio foschi wrote 101 lines
>> You can test this by typing the following in a browser address bar: http://localhost:3000/REST/metadata and you should get the metadata from the REST service. << I tried this but I dont get the metadata as expected. Instead, the browser displays the following message in json format { "error" : { "code" : 404, "message" : "NOT FOUND" } } >> (you may need to provide the username and password you configured in the rest bridge) << could you please expand on this? How do I provide username/password from the browser? When we talk about username/password do we mean one of the rows of table USERS? I run bufclient but the answer is always the same: 404 NOT FOUND What am I missing? Thank you Peppe On Wed, Oct 26, 2022 at 8:52 AM Michael Van Canneyt via lazarus wrote: > > > > On Tue, 25 Oct 2022, duilio foschi via lazarus wrote: > > > following the suggestions offered by zeljiko (thank you, zeljko), I > > was able to compile and successfully run > > demorestbridge.exe > > > > Albeit no message is displayed when the EXE starts, I can see that the > > application is alive and answering requests at port 3000 (I use > > command >netstat -bano for this). > > > > The next step I'd like to reach is to run a client demo that will > > communicate with the server above. > > > > Demo bufclient compiles successfully > > > > At start time, I need to insert data into 3 boxes: > > > > 1. URL > > 2. username > > 3. password > > > > #2 and #3 are no problem, of course. > > > > #1 puzzles me. > > > > The box has the following string preset > > http://localhost:3000/ > > > > To my poor knwoledge, http requires a web server and I have no web > > server running in my PC with windows 7. > > > > Is there any way to do a quick test of demorestbridge.exe without > > installing a web server? > > You don't need a webserver if you are using the demorestbridge. > > demorestbridge.exe itself acts as a webserver, it listens on port 3000. > > You can test this by typing the following in a browser address bar: > > http://localhost:3000/REST/metadata > > and you should get the metadata from the REST service. > (you may need to provide the username and password you configured in the > rest bridge) > > If that works, then in the bufclient demo, enter the URL > > http://localhost:3000/REST/ > > And push 'Get resource list' button to see a list of resources. > > Michael. > -- > _______________________________________________ > lazarus mailing list > > https://lists.lazarus-ide.org/listinfo/lazarus

Reply by email

zeljko
to duilio foschi
duilio foschi wrote 11 lines
I tried to run demorestbridge inside Lazarus in debug mode. When the web browser points to http://localhost:3000/REST/metadata the debugger shows an error message that says: 'project SQLDB REST bridge raised an exception of class 'EHTTP' with message: No REQUEST_METHOD passed from server.. At address 10009D512' Any idea what this could mean?

Yes, browsers by default do not send requested params (eg. request method). Use curl to test your server.
eg

curl -u YOURUSERNAME:PASSWORD -H "Content-Type: application/json" "http://localhost:3000/REST/metadata"

curl by default set request method to GET.
curl -u YOURUSERNAME:PASSWORD -H "Content-Type: application/json" -X GET "http://localhost:3000/REST/metadata"

If this results in error 400-40xx then you must include connection after REST eg http://localhost:3000/REST/YOURDEFAULTCONNECTIONNAME/metadata

zeljko

Reply by email

duilio foschi
to zeljko

Dear Zeljko,

If this results in error 400-40xx

this is exactly what happens :)

c:\>curl -u Detlef:secret -H "Content-Type: application/json" "http://localhost:3000/REST/metadata"
{
"error" : {
"code" : 404,
"message" : "NOT FOUND"
}
}

then you must include connection after

REST
eg http://localhost:3000/REST/YOURDEFAULTCONNECTIONNAME/metadata

gulp! Which is my default connection name?

Thank you

Peppe

PM zeljko wrote 31 lines
On 27. 10. 2022. 19:03, duilio foschi via lazarus wrote: > I tried to run demorestbridge inside Lazarus in debug mode. > > When the web browser points to > http://localhost:3000/REST/metadata > > the debugger shows an error message that says: > > 'project SQLDB REST bridge raised an exception of class 'EHTTP' with > message: No REQUEST_METHOD passed from server.. At address 10009D512' > > Any idea what this could mean? Yes, browsers by default do not send requested params (eg. request method). Use curl to test your server. eg curl -u YOURUSERNAME:PASSWORD -H "Content-Type: application/json" "http://localhost:3000/REST/metadata" curl by default set request method to GET. curl -u YOURUSERNAME:PASSWORD -H "Content-Type: application/json" -X GET "http://localhost:3000/REST/metadata" If this results in error 400-40xx then you must include connection after REST eg http://localhost:3000/REST/YOURDEFAULTCONNECTIONNAME/metadata zeljko

Reply by email

zeljko
to duilio foschi
duilio foschi wrote 22 lines
Dear Zeljko, > If this results in error 400-40xx this is exactly what happens :) c:\>curl -u Detlef:secret -H "Content-Type: application/json" "http://localhost:3000/REST/metadata" { "error" : { "code" : 404, "message" : "NOT FOUND" } } > then you must include connection after REST eg http://localhost:3000/REST/YOURDEFAULTCONNECTIONNAME/metadata gulp! Which is my default connection name?

check TSQLDBRestDispatcher.Connections, there should be at least one connection and check that connection name.

zeljko

Reply by email