GrazrScript Tutorial

Creating your first application

Now that you've learned the basics of GrazrScript it is time to create your own application. You can just read along, but the best way to learn a new programming language is to start modifying an existing program. Pretty soon you get ideas for something really cool you would like to do and you're off and running.

1. Download the example set

All of the examples in this tutorial are available in a zip file, so you can download them and unzip the files into any directory on your computer.

2. Edit a sample file

Inside the example zip file you will find two files that are meant as starting points for experimentation: inlinestart.xml, which uses the inline template format, and outlinestart.xml, which uses the outline format. Choose one of them and open it in any text editor. For this example, we'll try the inline starting file.

http://docs.grazr.com/script/tutorial/inlinestart.xml
<?xml version="1.0" encoding="UTF-8"?>
<opml version="2.0" xmlns:grazr="http://docs.grazr.com/script/spec/1.0">
<head>
<title>My Title</title>
</head>
<body>
<grazr:form name="searchform">
My Search <input type="text" name="subject" />
<input type="submit" value="Enter" />
</grazr:form>

<grazr:formtemplate name="searchform"
file="http://news.google.com/news?q=%subject%&amp;output=rss" />

<grazr:formresult text="Results of my search:" name="searchform" />

</body>
</opml>

3. Replace the formtemplate URL

A good place to start in creating a new GrazrScript application is finding a new feed-based query to use in the template section. We've already given Google enough free publicity, so let's try building a blog search application based on Technorati.com. The best way to figure out how the feed URL for a site works is to just use their search form and then look for an RSS link for the same results. Try this simple procedure with Technorati:

  1. Go to the home page of Technorati.com
  2. Type in a sample search. If in doubt, try the traditional "test".
  3. See if the results page has a link to a feed for this search. Sure enough, at the top right corner of the page there is a "subscribe" link with the following URL: http://feeds.technorati.com/search/test
  4. Copy the feed URL using your browser's standard procedure, and paste it into the template section of the program, replacing the original URL for Google News.
  5. Modify the URL to accept the value of the form field. In this case the new URL would be http://feeds.technorati.com/search/%subject%.
  6. Change the title, form prompt, and result text to match your new application, and save the file with a new name. Something like myfirstapp.xml would be good.

<?xml version="1.0" encoding="UTF-8"?>
<opml version="2.0" xmlns:grazr="http://docs.grazr.com/script/spec/1.0">
<head>
<title>Technorati Blog Search</title>
</head>
<body>
<grazr:form name="searchform">
Technorati Blog Search <input type="text" name="subject" />
<input type="submit" value="Enter" />
</grazr:form>

<grazr:formtemplate name="searchform"
file="http://feeds.technorati.com/search/%subject%" />

<grazr:formresult text="Technorati Results:" name="searchform" />

</body>
</opml>

3. Upload the new program

In order to use your new GrazrScript file you'll need to post it somewhere that can be reached over the Internet. Grazr Corp. offers free upload and hosting of GrazrScript applications at its website. You can create a free account at http://grazr.com/register. The tutorial version of this new file can be found at http://docs.grazr.com/script/tutorial/myfirstapp.xml.

4. Test it in Grazr

Now you can try your new application in Grazr by going to our configuration page, and pasting in the URL for the new file. If you did everything right, it should like this:


If you can't get this to work, don't be reluctant to ask for help.

5. Rinse and repeat

This is the essence of any programming language. Experiment with different URLs and form designs. Try the outlinestart.xml file and add several feeds for the same search form. Each time you change the file you will need to upload it again, and then reload it into the Grazr configuration page. You can keep this page open in a browser window, and press the Update button to display the new version of the file.

6. Install it on your page

When you have an application that you want to share with the world, you can follow the instructions on the configuration page to add it to a blog or any other Web page.

7. Share it with your friends

Be sure to tell everyone you know about your new toy. The configuration page will even provide you with a link to your application that you can send in an email or IM.

Where are the parts?Field substitution