Forum OpenACS Q&A: How to create a simple 3rd party web service?

The fact that I can't tell if this is a brain-dead question suggests to me that it may not be. If it is and there is an appropriate RTFM, please point me to it. I can't find discussion of this exact topic in this forum.

Suppose you have an OpenACS module that delivers some data and you want to enable other web sites to embed that content within a page of their own design, much as if they were embedding an image whose source is your OpenACS site. And suppose the key feature is that to accomplish this must require virtually no effort or maintenance on the part of the other web site; they should be able to edit their page once to point to the OpenACS module (ie tcl page) and then forget about it.

What is the best mechanism to accompish this?


Posted by John Lowry on
If you are willing to accept Javascript, here are instructions on how it was done by Loquacious.
Posted by Stan Kaufman on
Thanks John! Simple, elegant, and by Philip to boot. Now that you point it out, I recall reading this about a year ago. Too many mad cow burgers in the interim I guess.
Posted by Jerry Asher on
RSS can be used for this, and is being used for this in many situations.  It's not the be all and end all as the data to be published as to fit a relatively simple paradigm: a list of items, where each item basically contains enough info to create a nicely formatted hyperlink, that is, a description and a url.  There are some extensions to RSS that enrichen the model, but that increases the maintenance on the other website.  The power of RSS is that it is a standard way of publishing data that does fit a lot of data, and so it does make it easy for other webservers, web applicaitons, or browser based javascripts to receive and format the data.

But there are a couple of steps that are just not there yet.  You write, "much as if they were embedding an image whose source is your OpenACS site".  That's a tough one.  Embedding an image is a simple as sticking in a url, right?  Well to all of our great regret, there is no such thing as a client-side, html include file, and so you need something on the other side, either client browser or web server to read the published data and stick it into the client's browser's document.

So they will almost certainly not be able to just edit their page once to point to the module and then forget about it, not unless their basic web page application technology includes some sort of publishing/subscribe technology.  There are however RSS "subscription" scripts out there in perl, javascript, and other stuff, so it may be a good starting point.

Posted by Stan Kaufman on
I'm not sure what exactly Loquacious does on Philip's server, but here's one way to work it. To push dynamic content onto a non-OpenACS server's static page, you carve a spot in the static page by placing this Javascript snippet:
<SCRIPT LANGUAGE="JavaScript1.2">

with (document) {
write("<SCRIPT LANGUAGE='JavaScript1.2' SRC=''>");

Just do whatever DB stuff you want and append everything into a string and then ns_write it out at the end of the yourtcl.tcl page on your OpenACS site, thus:
set result [getallmyinfo ... ]
ns_write "document.write('$result');"
Thats all there is to it. I'm amazed.
Yes, it's pretty rat simple (I'm the author of the code).

BTW, you could add a lot of value by wrapping DIV tags around
the content so that your consumers can style the content any
way they'd like.

Incidentally, note that some (all?) javascript interpreters will choke on apostrophe's and control-M's. You'll need to regsub them out.
More accurately -- you'll need to backslash-escape the apostrophes and regsub out the ctrl-m's.
Posted by Stan Kaufman on
Andrew, my hat's off to you! Great concept, cool solution!

And thx for pointing out the additional subtleties.

Jerry, thanks for the explanation re RSS. It looks like the more robust method for sophisticated feeds, and I'll investigate it. But the Javascript redirection works for me now.
Posted by Stan Kaufman on
Once one has inserted dynamic information from an OpenACS server into a static page from a different server, does anyone know how Google handles this composite page when it trolls through?

In particular, if what the OpenACS server injects into the page is links to various other sites, would Google count those links as coming from the static page site or from the OpenACS site when calculating its notion of "page relevance"?

What I'm noodling with here is a concept of a centrally-managed DB-stored set of links that allied organizations who run simple static sites could incorporate into their pages in order to provide Google with a mutually-pointing, interconnecting set of links to push up their Google "scores".

Think this would work? Seems to me that this is could be a simple but nifty little web service for networks of organizations.