How to consume HTTP POST service/API?

I have an external service that offers a HTTP POST API. One method returns an HTML, the other a (PDF or other) document. How can I call these from Mendix and especially how can I use the result - either a document to save or to download or an HTML-page to show to the user or to redirect to? NB: I am aware of the mendix 5 RestServices-module and the mendix 6 native REST-support, but I am not sure whether I use it right as I get a 302-response which neither can handle.
2 answers

I think your struggle is that the service is returning a browser instruction (302 - redirect), while the Mendix RestServices and native REST support are both run server-side, not in the client's browser.

You have 2 options:

  • find a way to perform this POST on the client side (possible via the HTMLSnippet widget or a custom widget)
  • adjust the RestServices Java code to handle a 302 and download the HTML or PDF file to a location on your Mendix server where you can then serve it back up to your client's browser.

Currently we don't support binary result. However, the exportStream API returns an inputstream, so you can store the result in FileDocument. This requires some Java Action works though.