I have a http post function in the backend of my site and i would like it to return text/html as the Content-Type which i have set in the options. Although when I call the function the responses Content-Type is application/json.
Below you can see my code
export function post_acsexit(request) { let options = { "headers": { "Content-Type": "text/html", }, "body": "<html><body>tt</body></html>" }; return ok(options); }
What if I need (as I do, in my specific case), to return a tiny piece of script that will be rendered inside an iframe after the submission of a form, and trigger navigation on the parent page?
You can do that.
https://support.wix.com/en/article/corvid-working-with-the-html-element
https://www.wix.com/corvid/reference/$w.HtmlComponent.html
@givemeawhisky , thanks so much for your reply. But I'm still not clear. Generally when something is a 'default' that means it takes on that value (in this case 'application/json') if none other are specified. But here it's not acting as a default, but rather as a static value that cannot be overridden.
This is not the documented behavior (unless I've overlooked something), though you are correct that all the documented examples show 'application/json' as the specified value for headers.content-type.
If the value will always be 'application/json' then why show examples of it being specified at all?
Everything else is working just fine so I'm not having any issues with testing or publishing the http functions.
That is because the default Content-Type for Wix is application/json.
If you look through all of the Wix API reference for Wix HTTP Functions and it's Wix Support pages too, you will find that it is all application/json.
https://www.wix.com/corvid/reference/wix-http-functions.html
https://support.wix.com/en/article/corvid-exposing-a-site-api-with-http-functions
Also note:
You must publish your site at least once before using both the testing and production endpoints. After that, you save your site for changes you make to testing endpoints to take effect and you publish your site for changes you make to the production endpoints to take effect.
How do I debug an HTTP function?
Each HTTP function you create has two endpoints, one for your users and one for you to use for testing. The testing endpoint is similar to the regular one, but the suffix -dev is added to the _functions in the URL. You can send requests to your testing endpoint in whatever way is most convenient for you, such as using a third-party tool like Postman. Learn more.
I have exactly the same issue. Regardless of what I set the content-type to in my response.headers, the actually HTTP response (as shown by command line tools) is always 'application/json'.
Can anyone shed light on this?!
Here's my code:
export function get_htmlcode(request) { const headers = { "content-type": "text/html" }; response.headers = headers; response.body = `<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><body><b>hello</b> world</BODY></html>`.trim(); return ok(response); }
Here's a snippet showing result of curl -v from command line.
> GET /website-2/_functions-dev/htmlcode HTTP/1.1 > Host: webmaster4byoweb.wixsite.com > User-Agent: curl/7.54.0 > Accept: */* > < HTTP/1.1 200 OK < Date: Tue, 17 Sep 2019 19:45:13 GMT < Content-Type: application/json < Content-Length: 95 < Connection: keep-alive < server-timing: ttfb=0.644; "Time to first byte"