Main Board > Web Services

Custom content for http error responses

<< < (2/2)

Mike King:

Just an FWIW: In PxPlus 2021 due in May we have added a new global variable %Exit_include_html which you can set when you set %Exit_code to indicate you want the output you have placed in %PRINT_FN to be used along with the status code; something like this:

  json$["errors.1.title"]="INVALID FORMAT"
  json$["errors.1.detail"]="invalid query paramete"
  Write Record (%print_fn) DIM(LIST EDIT json${ALL})

We have this exact program setup on at so you can see the output which was based on the desired output that originally started this thread.

As for other REST style services our web services, available since PxPlus 2014, can be used to provide charts, reports, lists, and other data on demand -- suitable for use with JavaScript or other applications.  For details see:

Jeff Wilder:
Thank you Mike. That is excellent! I can't wait to try it out.

Dirk, I wrote my REST web service for the PxPlus web server before PxPlus 2014 was available. If doing it today, I would most likely use the method Mike referenced in the manual.


St├ęphane Devouard:

At my last PxPlus job, I wrote a web service for CRUd operations on the main resources in the system (vendors, customers, employees, jobs, etc...)
No actual Delete operations were allowed -- but an update operation setting the ACTIVE field to false was roughly equivalent to deleting a record ;)

I used the IIS CGI interface as the product was installed exclusively on Windows servers
Only GET & POST operations were initially available, and the payload / body part of the requests was XML

I reworked a second version of this stuff, but I don't think it has been deployed after I was let go

The second version was using the URL Rewrite module in IIS to redirect requests to a front-end controller using an URL pattern
GET becomes
POST becomes
PUT becomes

Then the restapi.pxp front-end controller would parse the HTTP headers for authentication and authorization, the route$ CGI variable for the entity/resource identification, the payload as well as the HTTP method to call the appropriate CRUd routine and perform the database operation.

Hope this helps


[0] Message Index

[*] Previous page

Go to full version