Showing posts with label URI. Show all posts
Showing posts with label URI. Show all posts

Tuesday, June 22, 2010

Grails multiple web sites, same web application

We had a need recently to have one web application serving many web sites, where the same data schema was in place with data shared across multiple web sites, but we wanted to show different styling and different data depending on the URI. In the end it turned out to be fairly simple. With our naming conventions, it's possible to hit one of several URIs for the same site, such as:

* project.testing.com
* project.staging.com
* project.com

So I had created a domain lookup service that when passed the request URI could work out what site the request for targeting.


def targetUri = request.getServerName()


I did a lookup for that target name against an object stored in the database relating to that targetUri and passed that back, making it available for queries for the correct data to show, and passing that down into the views to render the relevant CSS and Javascript files.

Thursday, April 03, 2008

URI as Contract

When working on Mojo, one of the first things we did was to come to an agreement on the API that the application would use. I think we went in this direction early as we had always intended for the Mojo to be used as an 'widget' platform to access the Web21C SDK Services. I think it was a great move, and I'd certainly recommend this, even if you don't intend your web app to have an API.

With modern REST based web apps, we tend to think about the URI a lot more along with what to POST or GET to that URI. There are no real rules, and as such - toolkits, to help the developer with building REST-friendly URIs, it's more of a mind set. I won't repeat those rules here, but it essentially boils down to cool URIs and being mindful of resources.

The part where can come stuck is thinking in terms of actions or methods, it's something we all have to get used to, but I truely believe that if you invest a little time to agree URI as contract, it'll save headaches later on.