Web Connection
Rest service responses other than JSON
Gravatar is a globally recognized avatar based on your email address. Rest service responses other than JSON
  VFPJCOOK
  All
  Apr 22, 2024 @ 03:52am

Rick, My website (mostly reactjs) needs the photos for menu items like Snickers candy bars. I know the website can not see the server's hard drive. The photos are stored on a server and the website can determine the name by something like .jpg My questions is what is the best way for the website to retrieve the photos? I am already providing the website with a path to where the photos would be located. I believe that path would need to be a url. Does that mean I could put the photos in something like deploy\menuitemphotos and they would be available to the website. I was trying to find the web connection documentation that talks about REST responses being pdf's or other things rather than JSON but can not find that documentation. Thanks, john

Gravatar is a globally recognized avatar based on your email address. re: Rest service responses other than JSON
  Rick Strahl
  VFPJCOOK
  Apr 22, 2024 @ 09:30am

Yes you can return non-JSON responses from a REST service:

FUNCTION RestReturnPdf()

*** Force non-JSON response
THIS.oJsonService.IsRawResponse = .T.
Response.ContentType = "application/pdf"

*** File needs to be in the `/web` folder hierarchy
lcFilename = THIS.ResolvePath("~/policy.pdf") 

*** Send from memory - string/blob
lcFile = FILETOSTR(lcFilename)
Response.BinaryWrite( lcFile )

*** Send from file
*!*	 Response.TransmitFile(lcFilename,"application/pdf")

ENDFUNC

Incidentally I added a new lRawResponse property to the wwRestProcess class that basically forwards to the THIS.oJsonService.IsRawResponse to have a more easily discoverable direct property to use.

It'll be in the next update.

+++ Rick ---

© 1996-2024