• Create Your Own RSS Feed in Grails

    Posted by Ankit Nigam | Last Updated: 21-Apr-14

    Hi Guys.In todays time we have a need to keep our websites updated with all the latest information & content , so that the visitors will keep on getting all the relevant updates regarding their relevant topics or themes.
    Rich Site Summary, also known as RSS feeds commonly are mostly used by the site administrators to provide the visitors with the latest updates regarding new Posts ,Blogs etc, in a common format.These are basically XML files with some metatags like "link","author","description" etc which provide the details of our blogs & updated contents.These XML files are parsed into formatted content using RSS Reader , News Reader etc tools to show updated content to the visitors.
    In order to have our own RSS feeds what we need only is a view & a controller for that view.
    Lets suppose we have a domain BlogEntry which stores the data of the bolgs in our site and what we want is to have our feeds shown at /feeds url in browser.
    So we can generate a controller simple like :
    class FeedsController {
        def index = { 
    		SimpleDateFormat rssDate = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z")
    		def blogList = BlogEntry.list([max: 10,order :"desc",sort:"id"])
    		[blogs: blogList, formatter: rssDate,serverUrl : grailsApplication.config.grails.serverURL]
    Here we have set the response content-type as XML , so our output page will be an XML instead simple html and content will be parsed like an XML page which is required for RSS.
    The second thing to note here is the date-format.This should be very specific as the date shown & parsed in the RSS Readers is in full (EEE, dd MMM yyyy HH:mm:ss Z) format.
    The respective index.gsp should be written as :
            Oodles Technologies Blog contains exclusive content on different categories of Software Development, Mobile App Development,Groovy Grails,SaaS, Video Content.
            ${formatter.format(new Date())}
                ${serverUrl}<g:createlink controller="blog" action="showEntry" ]"="">
    The attributes used in the above XML are metatags which are used to give additional information about your site & specific posts or blogs.You can add additional pre-defined metatags based on your requirements.
    Do give the above method a try instead of using any plugin as it is easy to understand,fully customised & hassle free approach.

Tags: grails , xml

Mobile Applications

Video Content

Bigdata & NoSQL

SaaS Applications



Alexa Certified Site Stats for