I am using Oracle rest data service. So I need to program a respond to a particular request. For an example,
I get a request in application Express ORDS,
request_body BLOB:= :body;
Now I need to create a respond for this request. Like,
respond('application express ok'); // this sends to the client
thank you!
You should also provide document type and status code (and any other headers you can think of.
Example: JSON:
begin
owa_util.status_line (200, '', false);
owa_util.mime_header ('application/json', true);
htp.prn ('{"status":"everything is a ok"}');
end;
Text:
begin
owa_util.status_line (200, '', false);
owa_util.mime_header ('text/plain', true);
htp.prn ('everything is a ok');
end;
And a bit bigger example using headers:
declare
l_response varchar2 (32767);
begin
l_response := '<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Response</title>
</head>
<body>
<h2>Thank you for submitting</h2>
</body>
</html>';
owa_util.status_line (200, '', false);
htp.p ('Content-Type: text/html; charset="iso-8859-1"');
htp.p ('Content-length: ' || trim (to_char (length (l_response), '999999999999999999')));
owa_util.http_header_close;
htp.prn (l_response);
end;