Main Board > Web Services

Custom content for http error responses

(1/2) > >>

Jeff Wilder:
I have a REST web service running under the PxPlus Web Server 15.10.0001. I would like to have custom content when the service responds with an HTTP error code. No matter what I try, the web server responds with the following standard HTML message after setting %Exit_Code=400.

--- Code: ---<html>
        <title>400 Bad Request</title>
        <h1>400 Bad Request</h1>
        <p>The Requested URL is not properly formed.
Method: GET  URI:/restapi.pvp  ARGS:
--- End code ---

How can i override this behavior to force a response with my own content? I tried adding a record to the *web\websrv.tpl with no luck.

My web service needs to respond with something like:

--- Code: ---{
  "errors": [
      "status": 400,
      "code": 4077,
      "title": "INVALID FORMAT",
      "detail": "invalid query parameter format",
      "source": {
        "parameter": "date",
        "example": "2019-03-09"
--- End code ---

St├ęphane Devouard:

How about setting CONTENT_TYPE$ to application/json and
either EXIT_TEXT$ to your JSON error message
or write your JSON data to %print_fn ?

Jeff Wilder:
I have set %Content_Type$ and printed output to %PRINT_FN, but the web server continues to serve up a generic HTML page. I had never heard of setting EXIT_TEXT$. I just tried EXIT_TEXT$ and %EXIT_TEXT$ with no change.

St├ęphane Devouard:
Sorry, I was thinking about %EXIT_TEXT$ but forgot the leading % when posting my response

Well, I guess you're using the Web Services stuff embedded within the newer versions of PxPlus

So far, any and all web services I have written in ProvideX were using V10 or prior versions, so were just CGI programs launched from Apache/IIS which were parsing incoming XML data and writing back XML responses to %PRINT_FN with the appropriate %CONTENT_TYPE$ and %EXIT_CODE set, and no pre-defined HTML was getting in the way if I happened to return anything else than an HTTP 200/201

So either you need to do the same, or I guess the Web Services maintenance interface needs some improvement on the PxPlus side with settings to either prevent it to spit out its predefined HTML pages in case of an HTTP 4xx ou 5xx status, or hooks to define special responses for special HTTP statuses


how did you write a real REST web service with providex ?
i wrote hundrets of different singel services for xml and json data, but i have no idea how to implement a real REST webservice in providex.
Maybe someone can give me a clue.

I am also interested how other people do the error handling, becuase i am not able to transfer the status code 400 back to the clients.



[0] Message Index

[#] Next page

Go to full version