PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Apache HTTP Interface  (Read 1916 times)

bteixeira

  • Silver Member
  • ***
  • Posts: 27
    • View Profile
Apache HTTP Interface
« on: February 20, 2019, 05:02:24 PM »
I'm looking to implement some web APIs (json or xml).  The Apache HTTP Interface looks to be basically what I need but the setup documentation implies that PxPlus needs to be installed on the Apache server.  Can I use the interface if I want to separate the web server and my application on different boxes?

Mike King

  • Diamond Member
  • *****
  • Posts: 3811
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: Apache HTTP Interface
« Reply #1 on: February 20, 2019, 06:55:25 PM »
No -- Apache uses a CGI interface to launch your PxPlus program which requires a copy of PxPlus to be installed on the Apache server. 

If running iNomads, you can (with PxPlus 2018), have the PxPlus on the Apache server forward the requests to a separate application server where the actual application is executed.  Perhaps this would get you what you are looking for.

Alternatively you may be able to redirect the requests using Apache to your machine and then just run a copy of Apache on your application server.  Have a look at the Apache "Reverse Proxy" capabilities.

Here is a link that may help provide you some guidance:
https://httpd.apache.org/docs/2.4/howto/reverse_proxy.html

This would avoid having to have PxPlus installed on the Internet facing server.

NOTE: The above link includes discussions about load balancing which require additional setup if using iNomads as requests need to go to a specific/consistent host.
Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com

bteixeira

  • Silver Member
  • ***
  • Posts: 27
    • View Profile
Re: Apache HTTP Interface
« Reply #2 on: February 21, 2019, 08:25:58 AM »
Can you use iNomads to generate an xml or json file instead of displaying a panel?  I know you can specify a program to run instead of a panel but I don't see anything equivalent to the %print_fn channel.

Mike King

  • Diamond Member
  • *****
  • Posts: 3811
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: Apache HTTP Interface
« Reply #3 on: February 21, 2019, 09:27:15 AM »
Assuming you are running iNomads you likely have an E-Commerce license which means you can use the standard Apache interface to generate and return XML or JSON.

In fact we supply a Nomads Query based Web service with PxPlus that returns XML or JSON data.  Check out our Web Services documentation at https://manual.pvxplus.com/page/PxPlus%20Web%20Services.htm

Alternatively you can create your own CGI scripts that run PxPlus to create and output XML or JSON data files that the CGI script can return.
Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com

bteixeira

  • Silver Member
  • ***
  • Posts: 27
    • View Profile
Re: Apache HTTP Interface
« Reply #4 on: February 21, 2019, 09:30:51 AM »
I'm more asking, since I know iNomads lets you keep the application server separate from the web server, can I use iNomads to generate the XML/JSON response rather than doing the Apache reverse proxy you mentioned before.

bteixeira

  • Silver Member
  • ***
  • Posts: 27
    • View Profile
Re: Apache HTTP Interface
« Reply #5 on: February 21, 2019, 04:19:53 PM »
Mike,
     I did some digging into in_proc, in_send and in_recv and came up with the following code that looks like it does what I want:

00010  let OUTFILE=%INOMADS'TCPFILE
00020  let TO_OUTPUT$="<?xml version="+quo+"1.0"+quo+"?><outside><first>Ben</first><last>Teixeira</last></outside>"
00030  let TO_OUTPUT$+=$0D0A$
00040  if len(TO_OUTPUT$)>9000 \
        then write record (OUTFILE,err=*next)ior($8000$,bin(8000,2))+mid(TO_OUTPUT$,1,8000);
             let TO_OUTPUT$=mid(TO_OUTPUT$,8001);
             goto *same
00050  if not(nul(TO_OUTPUT$)) \
        then write record (OUTFILE,err=*next)bin(len(TO_OUTPUT$),2)+TO_OUTPUT$
00060  remove (OUTFILE,err=*next)
00070  end

I just set up a transaction with this program and no exit url.  Using *plus\web\request the response is exactly right.
This works, but I'm hesitant to use something like this, sort of going around the back of iNomads.  Who knows what might change in future versions of PxPlus?

As a wishlist item, could we get something in iNomads where you could specify that a transaction is a REST request and we could write a program similar to the above (or better just set something like %inomads'rest_response$) that would handle the response?