Getting Started with the Sausalito Core SDK

Creating a new Project

In order to build your Sausalito Application, you need to create a project. Essentially, a project is a set of directories that contain your code, static files, configuration information, and test data. Every project is identified by a logical URI (e.g. http://www.28msec.com/myapp/). This concept is similar to Java packages. The sausalito script provides an easy to use way to create such a project. The syntax to create a project is as follows:

sausalito create project -d <project_directory> -u <project_logical_URI> 

The parameter project_directory is the target directory on your PC or Mac in which all files or your project are kept.

For example, to create a new project with the logical URI http://www.mydomain.com/myapp/ (project_logical_URI) in the directory myapp on your machine just type

sausalito create project -d myapp -u http://www.mydomain.com/myapp/

You should see an output such as

Creating project at: myapp
Project URI:         http://www.mydomain.com/myapp/
Project created successfully

and have the directory myapp created in your current working directory. Please note that the prefix http://www.28msec.com/ is reserved for namespace URIs.

Testing the New Project

sausalito test project -d <project_directory> [ -i <ip:port> ]
Deploys the project on your machine. That is, a Web server is started on your machine and you are now ready to test your application using a Web browser. When you created the project, Sausalito already created a small “hello world” mini-application for you. (You will learn how to edit and extend it later.)

Per default, the test server is bound to localhost:8080. However, if you wish you can set a different IP address and port. This is important if you would like to run several applications at the same time.


Example:

sausalito test project -d myapp

Now you can start your Web browser and call the following URL:

http://localhost:8080/default/index

You should see a nice green Web page. In fact, you have executed the “index” XQuery function in the “default” module of your pre-configured mini-application. Also try:

http://localhost:8080/unknown

You should see an error because there is no “unknown” module in your mini-application.

Editing a Project and Some Playing Around

Once you have a running project you can start extending and customizing the code. With Sausalito, the whole application can be written using XQuery. So, let us edit the XQuery code. Start your favorite editor and edit the following file:

vi myapp/handlers/default.xq

You can play around with the HTML and the XQuery in this file while the application is deployed. Simply reload the page in the your Web browser to see the effects. You can also add other XQuery functions. If you write a new XQuery function “foo” in the “default” module, then you call this function in your Web browser as follows:

http://localhost:8080/default/foo

You can also pass parameters to your XQuery functions. For instance, try out what happens if you call the following URL in your Web browser (look at the “Parameter” lines at the bottom of the Web page):

http://localhost:8080/default/index?green=great&blue=over

If you want to see how bigger applications are built and what Sausalito and XQuery can do for you (e.g., libraries, database persistence, schemas, RESTful services, etc.), then take a look at the two demo applications that are shipped with Sausalito: Guestbook and TODO.

Deploying a Project

Once your project is created, debugged, and tested locally on your machine, it can be deployed on 28msec's scalable infrastructure. This way, your application becomes visible to everybody on the Web.

Here's what you need to do in order to deploy the “myapp” application:

  1. If you have not done so yet, create an account at http://28msec.dyndns.org:8080, the portal to manage the deployment of applications.
  2. Log into http://28msec.dyndns.org:8080. Click on “Applications” in the left menu. Click on “Create new Application”. Choose a name for your application; e.g., “myapp”. This name must be globally unique so you may receive an error that the chosen name is already in use. If you get that error, chose a different name; e.g., “myapp28”.
  3. Deploy your application using the following command

sausalito deploy project -d <project_dir> -a <project_name> The “project_dir” as chosen on your local machine when you created the project. “project_name” as chosen in Step 2 (e.g., “myapp28”). For example, call the script in the following way in order to deploy the “myapp” application located in the directory “myapp” and deploy it as “myapp28”:

 sausalito deploy project -d myapp -a myapp28

When running the script, the script will prompt you for a user name and password. Please, enter the same user name and password that you chose in Step 1 for managing your applications in the 28msec portal.

The script will upload your XQuery project (i.e., the XQuery source code) and start a Web Server to serve requests for your applications. Once you have run this script, you can do the following things:

  • Run your application by opening your browser and visiting http://myapp28.28msec.dyndns.org/default/index.
  • Monitor the status of your application by logging into the portal at http://28msec.dyndns.org:8080. In the portal, you can also stop or delete the application.
  • Upload a new version of your application. Re-running the “sausalito deploy project” script will upload and deploy a new version of your application, thereby overriding the previously updated XQuery code. If you would like to maintain several different versions of your application code, then you can do that as described here.
  • Upload seed data for your application (e.g., a pre-defined “admin” user for your application). More details on how to do this can be found here (Working with collections).
 
 
 
core_sdk_getting_started_guide.txt · Last modified: 2009/07/14 15:55 by mbrantner
 
Recent changes RSS feed Creative Commons License Valid XHTML 1.0 Valid CSS
backlinks | direct link: [core_sdk_getting_started_guide]