Back to overview

Creating a RSS feed

▼ Post information

Author Jef Meijvis Publish date 25/07/2023
Title Creating a RSS feed Id 17
Source 017-creating-a-rss-feed.md Render timestamp Dec 06, 2023, 06:08:31 AM (GMT+1)
Views 22 Tags OpenInternet
Author Jef Meijvis
Publish date 25/07/2023
Title Creating a RSS feed
Id 17
Source 017-creating-a-rss-feed.md
Render timestamp Dec 06, 2023, 06:08:31 AM (GMT+1)
Views 22
Tags OpenInternet
opengraph

▼ Table of contents

Share this post:

Creating a RSS feed

Recently I added a RSS feed to my personal blogging site. RSS (RDF Site Summary) is a web feed technology, allowing programs to get updates from websites in a standardized fashion. Applications (called aggregators) can collect updates from different RSS sources, and display them in a custom newsfeed. RSS is mostly used for websites that update frequently such as blogs, podcasts and news sites.

RSS Logo

Image: RSS Logo

What is RSS

When queried, a RSS feed displays channels containing generic items. This data is provided as a XML file, which then can be read by appropriate applications. Below code snippet is an example of a RSS feed with one channel, containing 2 items:

Code snippet

1
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
2
    <channel>
3
        <atom:link href="https://www.jefmeijvis.com/rss" rel="self" type="application/rss+xml"/>
4
        <title>Jef Meijvis</title>
5
        <link>https://www.jefmeijvis.com</link>
6
        <language>en</language>
7
        <description>Blogging about general secure software development. Often making use of .NET, Azure and Svelte</description>
8
        <image>
9
            <url>https://www.jefmeijvis.com/profile-picture.png</url>
10
            <title>Jef Meijvis</title>
11
            <link>https://www.jefmeijvis.com</link>
12
        </image>
13
        <item>
14
            <title>Microsoft threat modeling tool</title>
15
            <link>https://www.jefmeijvis.com/blog/016-microsoft-threat-modeling-tool</link>
16
            <description>Making use of the official Microsoft threat modeling tool.</description>
17
            <guid isPermaLink="true">https://www.jefmeijvis.com/blog/016-microsoft-threat-modeling-tool</guid>
18
            <source url="https://www.jefmeijvis.com/rss">Jef Meijvis</source>
19
            <category>Security</category>
20
            <enclosure url="http://www.jefmeijvis.com/post/016/logo.png" length="221004" type="image/png"/>
21
            <pubDate>Sat, 15 Jul 2023 11:33:10 GMT</pubDate>
22
        </item>
23
        <item>
24
            <title>Techorama, Gamify threat modeling</title>
25
            <link>https://www.jefmeijvis.com/blog/015-gamify-threat-modeling</link>
26
            <description>At Techorama Antwerp 2023 I gave a talk about gamifying threat modeling.</description>
27
            <guid isPermaLink="true">https://www.jefmeijvis.com/blog/015-gamify-threat-modeling</guid>
28
            <source url="https://www.jefmeijvis.com/rss">Jef Meijvis</source>
29
            <category>Security</category>
30
            <category>OWASP</category>
31
            <category>Cornucopia</category>
32
            <category>Talk</category>
33
            <enclosure url="http://www.jefmeijvis.com/post/015/logo.png" length="221004" type="image/png"/>
34
            <pubDate>Sat, 24 Jun 2023 11:33:10 GMT</pubDate>
35
        </item>
36
    </channel>
37
</rss>

Channels

The RSS tag contains channels. Each channel contains multiple items, as well as a bit of general information. The following 3 tags are required for a channel, here filled in with a made-up developer news channel:

Code snippet

1
<channel>
2
    <title>Developer News Channel</title>'
3
    <link>https://www.developer-new-channel.com</link>
4
    <description>The latest news for software developers all around the globe!</description>
5
</channel>

Items

Now if we want to do anything useful with RSS feed, we need to publish some items. An item is a child element of a channel and only needs a required title or description like so:

Code snippet

1
<channel>
2
    <title>Developer News Channel</title>'
3
    <link>https://www.developer-new-channel.com</link>
4
    <description>The latest news for software developers all around the globe!</description>
5
    <item>
6
        <title>
7
            Svelte rises in popularity!
8
        </title>
9
        <description>
10
            The javascript framework created by Rich Harris, Svelte, keeps on rising in popularity according to the state-of-js survey
11
        </description>
12
    </item>
13
</channel>

Many other elements can be added to channels and items to include more information. An entire list with useful examples can be found at The RSS Specification.

Generating in Svelte

Since this blog is created using Svelte, I generate the RSS feed on the fly making use of an Sveltekit API endpoint. The source code for this endpoint can be viewed here on Github.

Code snippet

1
export async function GET({fetch,url}) 
2
{
3
    let body = ''
4
    // Iterate over every post, and generate an <item></item>, add this item to the body string
5
    return new Response(body,responseInit);
6
}

I use the following headers to indicate that the request serves a XML file.

Code snippet

1
// Header options
2
const responseInit : ResponseInit =
3
{
4
    headers : 
5
    {
6
      'Cache-Control': `max-age=0, s-max-age=${600}`,
7
      'Content-Type': 'application/xml',
8
    }
9
}

Conclusion

All in all, RSS is a great technology that is (in my opinion) really under-used. Aggregators availability and browser support for RSS has really shrunk over the past decade. In a time where the battle for an open internet is more relevant than ever (looking at you, Twitter) RSS seems like a great technological standard to allow automatic distribution of website updates.

Back to top