Servlet alternative to PB ?

Just starting out? Need help? Post your questions and find answers here.
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 635
Joined: Fri Dec 04, 2015 9:26 pm

Servlet alternative to PB ?

Post by skinkairewalker »

Hi everyone !
I am thinking here about servlets ...
Have a way to add on Webserver or Atomic Webserver this :
if user call : localhost:80/AWS_servlet , when AWS receive this "/AWS_servlet" , call some "procedure " inside AWS PB code ?
User avatar
the.weavster
Addict
Addict
Posts: 1537
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Re: Servlet alternative to PB ?

Post by the.weavster »

Hi skinkairewalker,

I'm not sure if I'm understanding your question correctly but... PB can compile CGI executables which you would usually put in the cgi-bin folder of your website. Lets say you've used PB's CGI command to create an executable named myapp.cgi and you were hosting it on a local web server then you could access it on http://localhost:80/cgi-bin/myapp.cgi

To get the incoming data from a POST request you use the ReadCGI() command to get the size of the buffer and PeekS(CGIBuffer(),BufferSize, #PB_UTF8) to get the body of the request. For routing a request to procedures inside myapp.cgi you could look at using JSON-RPC:

example request:

{"jsonrpc": "2.0", "method": "multiply", "params": [2,2], "id": 1}

myapp.cgi looks at the value of the "method" member and uses that to decide which procedure to pass the parameters to and the WriteCGIString() command is used to write the response back to the client:

{"jsonrpc": "2.0", "result": 4, "error": null, "id": 1}


This is the format for an error message:
{"jsonrpc": "2.0", "error": {"code": -32601, "message": "Method not found"}, "result": null, "id": "1"}
Post Reply