To handle an API message, you use a regular defop... what makes it a "web" API is that it uses the same HTTP protocol that a browser uses to fetch a web page or to post a form. In fact, you can often use a browser to try out a web API. For example, point your browser to http://friendfeed.com/api/feed/public, and you'll see a JSON message containing the most recent 30 public entries published to FriendFeed.
Here's an example of a very simple API written in Arc. For debugging, I have an op called "log" which will print a message in the window I'm running Arc in. So calling "http://myserver.com/log?message=hello" will print "hello" in my server window:
The (pr "OK") prints "OK" to stdout, which is returned to the client, so if you pointed your browser at http://myserver.com/log?message=hello you'd see "OK" displayed in your browser window.
To return JSON data like FriendFeed, you can either do it by hand:
Ok I found the mz patch you created, but it's a little confusing installing it.
I tried the "patch method" but obviously the command
"patch <mz.patch"
will not work in the arc top level. i am assuming you're running mzscheme directly to run this command (which i have never done).
I tried downloading your version of arc, but it doesn't work with or sync with "anarki". I get errors.
I find the whole library part of anarki extremely confusing.
As much as I am sure people are contributing valuable code, it's like it's a dumping ground with little documentation (some exceptions). People are throwing code in odd directories with odd names and no examples for usage.
wouldn't be nice to have an install like:
/arc/required/*.arc
/arc/recommended/patch/before/*.arc; for bug fix code that has to be loaded instead of the relative core arc or mzscheme code, as opposed to after.
/arc/recommended/patch/after/*.arc; for bug fix code that can be loaded after core arc loads, but before libraries.
/arc/recommended/libraries/*.arc;
/arc/optional/; no optional files or patch files for optional libraries to be in any 'recommended' directories.
/arc/optional/patch/*.arc
/arc/optional/patch/before/*.arc
/arc/optional/patch/after/*.arc
/arc/optional/libraries/*.arc
oh and while i'm frustrated.... an ide with a picklist for the optionals that figures out for us what dependancies are in place and manage them.
To date I have just been downloading the anarki directory, but tonight I'm going to try using the "git stable" method.
Question for you CatDancer, is your copy of Arc2 the equivalent of 'git stable' ?
I don't find I am using many of the optional features in anarki (so far I only use parsecomb and arcformat which are awesome) and if I do I was thinking I could drop them on top of your arc2 copy.
Were you able to get parsecomb to do anything? I was able to get it to make matches, but I couldn't figure out how to get it to tell me which match had been made. (For example, I could have it match a number or a string, but if it matched "123" I would get "123" returned to me but I couldn't figure out how to tell that it was a number that had been matched).
iirc, I ran parsecomb in pg's arc2 by removing the documentation strings from the beginning of the def's in the source.
thaddeus, I updated my documentation at http://catdancer.github.com/mz.html to give an explanation of the patch command and how to use it. Take a look and let me know if it's helpful. (Note github has come kind of caching bug with their pages so if you go back to the page your browser will display the old version of the page if it has a copy of it in its cache; you must click the refresh button or press F5 to see the new version).
I also crossed out the explanation of how to apply the patch using "git pull", since as you discovered "git pull" doesn't work if the two git repositories don't share a common ancestor. (I suspect there is a way to do this using git, but I'll have to go looking for it).
"patch" is actually a Unix command, it comes standard with Unix. So you'd type "patch <mz.patch" in your Unix shell, inside your arc directory.
If you're running Windows, if I remember correctly patch comes with cygwin... though I'm not sure.
If you look at mz.patch you can see that it is merely adding one line to ac.scm, so if all else fails, you can edit ac.scm and add the line yourself :-)
mz.patch is a patch against pg's original arc2... I have no idea if it will work with Anarki or not.
As a note for other n00bs who want to use the mz patch on anarki, it's probably best to just manually add the one line to the ac.scm file. Running the patch will fail with an error "patch already detected". I'm no unix expert but I looked at the anarki verion and there's already extra lines added where the patch expects to place it's code line(And the "add anyway" unix prompt failed for me).
At any rate I'm now playing with your json library CatDancer. Thanks for the help along the way.
T.
I have no idea why I used ((mz integer?) v) instead of (isa v 'int) in json.arc, it sounds like it would have saved you some trouble if you hadn't needed to install the mz patch first.