/**
*
* Description : A simple snippet to demonstrate how to use Google AJAX API in Vala programming language
* Vala version : 0.7.8
* Developed by : Emad Al-Bloushi
* Date : Thu 12 Nov, 2009
* Compile with : valac --thread --pkg libsoup-2.4 --pkg json-glib-1.0 GoogleTranslator.vala
* Refer to : http://code.google.com/apis/ajaxlanguage/documentation/#fonje
*
**/[indent=4] def default_handler(server : Soup.Server, msg : Soup.Message, path : string, query : GLib.HashTable?, client : Soup.ClientContext) response_text : string = "<html><body><p>Current location: %s</p><p><a href=\"/xml\">Test XML</a></p>
//compile with: valac --thread --pkg libsoup-2.4 main.vala -o soup_post using Soup; class rpc_request { private static rpc_request request_instance; private HashTable<string,string> args; private rpc_request() { args=new HashTable<string,string>(str_hash,str_equal); } public static rpc_request get_instance() { if(null==request_instance) { request_instance=new rpc_request(); } return request_instance; } public void add_parameter(string name,string val) { args.insert(name,val); } private string prepare() { Soup.URI myuri=new Soup.URI("http://
[indent=4] /* Build with "valac --thread --pkg libsoup-2.4 yourfile.gs */ uses Soup init var session = new Soup.SessionAsync () var message = new Soup.Message ("GET", "http://www.google.com") session.send_message (message) print ("Message length: %lld", message.response_body.length) print ("Message data: %s\n", message.response_body.data)
public class Main : GLib.Object { static void main (string[] args) { weak Thread thread_1; if (!Thread.supported()) { stderr.printf("Cannot run without threads.\n"); return; } try { thread_1 = Thread.create(doRequest, true); } catch (ThreadError ex) { stdout.printf("Error: %s\n",ex.message); return; } thread_1.join(); } public static void* doRequest (){ Soup.Session session; session = new Soup.SessionAsync();