2011-05-30

Using GWT as a RESTful frontend for a RESTful Go backend


Basically it doesn't work without hacks... The problem ist that the XMLHttpRequest cannot post or retrieve data to or from a location that isn't identical to the host where the application is running. So you can't run a GWT dev server on localhost:8888 and communicate with Go's backend which must run on a distinct port of you dev machine (e.g. localhost:8080). Of course you can compile your GWT frontend that communicates with the Go backend via REST and run it within the Go server environment. But this dev practice isn't exactly what's called "rapid" or even feasible at all.
 
In the case you want try it anyway: GWT's wrapper for XMLHttpRequest is the RequestBuilder class which is encouraged to be used instead of the raw XMLHttpRequest class which is available in GWT as well. You can find a nice explanation of how to use GWT as RESTful frontend in GWT's docs.
 
After all I will not give up my architectural approach to build a RESTful Go app. But now I will not use GWT as a frontend/UI framework but try to go raw with plain Ajax. Ok, not so raw as JavaScript "programming" used to be five years ago... I'll use Google Closure tools which are also used by Google internally to build apps like Google docs, Picasa any many more.
 
Update
 
Yes, you can write GWT frontend code for Go without starting GWT's embedded Jetty (-noserver flag) server!