0

I have a REST API with POST method and it works fine. But on a custom 400 status code error response the content-type seems to be html rather than json.

Sample:

400 , 79ms, 23 bytes

api_status_code: SIM400-05 connection: close content-type: text/html;charset=UTF-8 date: Mon, 13 Jun 2022 14:31:15 GMT transfer-encoding: chunked x-ords_debug: false

Invalid Account Number

I have tried adding "REST-Framework-Version" as 4 in my request header but still the error response is as html and not json.

Oracle APEX: 21.1 Oracle ORDS: 21

1
  • 400 is an HTTP protocol-level error, so it is returned as HTTP. JSON content will only be returned by a successful completion (HTTP status 200) of the API call.
    – pmdba
    Commented Jun 14, 2022 at 10:20

2 Answers 2

0

In your request include an Accept header.

curl -X POST --header 'Accept: application/json'

enter image description here

1
  • Hi Jeff, Thank you for the response. I am sorry I did not respond here, but I managed to solve this by adding "OWA_UTIL.mime_header('application/json');" before I print the body content, in my ORDS Handler Definition - PLSQL Source. Thank you again.
    – John
    Commented Jun 15, 2022 at 12:25
0

Add below header in PLSQL code before printing the response message

OWA_UTIL.mime_header('application/json');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.