Main Board > Web Services

Custom content for http error responses

<< < (2/2)

Mike King:
Dirk

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.status"]="400"
  json$["errors.1.code"]="4077"
  json$["errors.1.title"]="INVALID FORMAT"
  json$["errors.1.detail"]="invalid query paramete"
  json$["errors.1.source.parameter"]="date"
  json$["errors.1.source.example"]="2019-03-09"
!
  %content_type$="application/json"
  Write Record (%print_fn) DIM(LIST EDIT json${ALL})
!
  %exit_code=400
  %exit_include_html=1


We have this exact program setup on at https://www.pvxplus.com/march10.pxp 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:  https://manual.pvxplus.com/page/PxPlus%20Web%20Services.htm

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.

Regards,
Jeff

Stéphane Devouard:
Dirk


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
e.g.
GET https://www.myserver.com/api/customers becomes https://www.myserver.com/somefolder/restapi.pxp?route=/customers
POST https://www.myserver.com/api/customers/new becomes https://www.myserver.com/somefolder/restapi.pxp?route=/customers/new
PUT https://www.myserver.com/api/customers/010000 becomes https://www.myserver.com/somefolder/restapi.pxp?route=/customers/010000

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

Navigation

[0] Message Index

[*] Previous page

Go to full version