Thread:Project:Support desk/JSON response/reply (5)

It sounds to me like you are writing your own custom script. When a web browser visits some particular url, you want your custom script to run, and *only* the stuff printed by your script returned to the browser, with the header "application/json".

If I understand you correctly, there are 2 things you need to do: (1) write a script that sets the header and prints out the JSON text, and (2) set things up so that script gets run when a user enters the special URI in his web browser.

Part 1 is pretty simple. Here's an example with "bash". I hope you will find it simple to translate to Python or PHP or your favorite language:

begin file "hello.sh":

#!/bin/bash # 2015-02-12: started by David Cary # for a question at # https://www.mediawiki.org/wiki/Project:Support_desk # released under CC0 1.0 License or later. echo 'Content-type: application/json' echo '' # empty line here is important for CGI echo '{' echo '"text": "Hello, world!"' echo '}' exit 0

end file "hello.sh".

Part 2 is not as complicated as you might think. Put your script in some convenient location on your web server -- perhaps in the same directory as your "LocalSettings.php" file.

The default ".htaccess" file that comes with Mediawiki already tells the Apache web server to run the Mediawiki "index.php" or "thumb.php" scripts only if a file does *not* already exist at that location. (That's what the "!-f" and "!-d" options do).

If you are lucky, this will "just work" -- test by typing the URI that corresponds to that file in some web browser.

If that web browser shows you a copy of that script, you know that you've typed the right URI; but you'll have to diddle with some settings (set the execute permission, etc.) to get Apache to *run* your script and send the output to the web browser, rather than simply *copy* your script to the web browser.