Subscribe for automatic updates: RSS icon RSS

Login icon Sign in for full access | Help icon Help
Advanced search

Pages: [1]
  Reply  |  Print  
Author Topic: Returning HTML from a REST webservice  (Read 13857 times)
David H.
Posts: 158


« on: November 06, 2017, 04:22:37 pm »

Hi all,

I was wondering if there is a way that a BDL REST based webservice could return HTML back to a web browser based request? Currently the options appear to be Text, XML, Data and File. HTML sent as Text is interpreted by the browser as text which is not what I want.

If not then please could a feature request be added for this.

TIA,

David
Frank G.
Four Js
Posts: 48


« Reply #1 on: November 06, 2017, 05:53:09 pm »

Hi,
 
 There are two options :
  1/ You can send the HTML page as text, and if you specify the 'text/html' mime-type as Content-Type, the browser will interpret it as HTML

  DEFINE doc xml.DomDocument
  LET doc = xml.DomDocument.Create()
  CALL doc.load("myfile.html")
  CALL req.setResponseHeader("Content-Type","text/html")
  CALL req.sendTextResponse(200,NULL, doc.saveToString())

  2/ Or you can send the HTML page in XML if you specify the "xhtml" mime-type as Content-Type header.
  DEFINE doc xml.DomDocument
  LET doc = xml.DomDocument.Create()
  CALL doc.load("myfile.html")
  CALL req.setResponseHeader("Content-Type","application/xhtml+xml")
  CALL req.sendXmlResponse(200,NULL, doc)

Regards,
Frank

Reuben B.
Four Js
Posts: 1046


« Reply #2 on: November 06, 2017, 09:40:26 pm »

Hi David,

I have an example available at https://github.com/FourjsGenero/ex_htmlpagegenerator that illustrates the technique.  The README also has links to a site that is using this technique in production.  Note the ws/r in the following URL https://harness.hrnz.co.nz/gas/ws/r/infohorsews/wsd06x?Arg=hrnzg-Ptype&Arg=HorseDetails&Arg=hrnzg-DoSearch&Arg=TRUE&Arg=hrnzg-HorseId&Arg=27168 and the ws/r as you hover over some of the links in the resultant page.

Reuben


Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero
David H.
Posts: 158


« Reply #3 on: November 07, 2017, 09:07:22 am »

Thanks Guys. Just having one of those "do'h, of course!" moments :-)
Reuben B.
Four Js
Posts: 1046


« Reply #4 on: November 07, 2017, 10:06:54 pm »

I should also take the opportunity to plug two additions under Genero 3.10 that help out in this area.

1. The XSLTtransformer class http://4js.com/online_documentation/fjs-fgl-manual-html/#c_gws_xmlXSLTtransformer.html enables you to generate the HTML using XSLT transformations.  Essentially use your 4gl to produce an XML document of unformatted data, and then apply an XSLT Transformation to it to produce the resultant HTML.

2. The WSHelper API http://4js.com/online_documentation/fjs-fgl-manual-html/#r_gws_wshelper_apis.html provides three methods that are useful in interpreting what the RESTful Web Services receives in the request.


Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines