Skip to content
Jennifer Programming Language

feed API reference

Web syndication feeds: build and parse both RSS 2.0 and Atom 1.0 through one module. A feed is a value-semantic Feed (title, link, updated, entries) of Entry (title, link, id, published / updated, summary, content). The format is chosen when you build ("rss" or "atom") and detected from the root element when you parse, so the same Feed shape serves both - a feed reader, podcast client, news aggregator, or changelog-to-feed generator.

A call into the module rebuilds the Feed it is passed (module-boundary retag), so append many entries with one addAll, not add in a loop.

Parsing rides the xml library (entities, CDATA, Atom's namespaces); building emits escaped XML through the same. Dates go through time (RFC 822 pubDate for RSS, RFC 3339 updated for Atom); an unset date is the Unix epoch and is omitted on build. To read a feed off the web, http.get it and parse the body; the module itself needs no network, so it loads on both binaries.

parse is strict: a document that is not an RSS 2.0 <rss> with a <channel> or an Atom <feed> in the Atom namespace, a date that does not parse, an enclosure length that is not a non-negative integer, or an Atom type="xhtml" construct without its single XHTML <div> throws Error{kind: "value"} (the xml library's own error for malformed XML).

Import with import "feed.j" as feed;. See the feed guide for prose and examples.

Contents

NameWhat it is
addA copy of f with e appended to its entries.
addAllA copy of f with every entry in entries appended, in order.
buildRender f to feed XML in the named format: "rss" (RSS 2.0) or "atom" (Atom 1.0).
entryA new Entry with the given title and link (empty id / summary / content, unset dates).
entryAuthorA copy of e with its author set.
entryCategoryA copy of e with category appended to its category tags.
entryContentA copy of e with its full content set (Atom).
entryEnclosureA copy of e with a media enclosure set (the podcast / audio / video file).
entryIdA copy of e with its stable id set.
entryPublishedA copy of e with its published instant set.
entrySummaryA copy of e with its summary set.
entryUpdatedA copy of e with its updated instant set.
feedA new empty Feed with the given title and site link (no entries, unset date).
feedAuthorA copy of f with its author set.
feedCategoryA copy of f with category appended to its category tags.
feedUpdatedA copy of f with its updated instant set.
hasEnclosureReport whether an entry carries a media enclosure (a non-empty enclosure url).
kindThe feed format of text, by its root element: "rss" or "atom".
parseParse feed XML into a Feed, detecting RSS vs Atom from the root element.
Enclosurestruct: A media enclosure attached to an entry: the podcast / audio / video file.
Entrystruct: One feed item.
Feedstruct: A syndication feed: channel-level metadata plus its entries.

Functions

add

jennifer
feed.add(f as Feed, e as Entry)

A copy of f with e appended to its entries.

f
the source feed
e
the entry to append
Returns Feed
the feed with the entry added

addAll

jennifer
feed.addAll(f as Feed, entries as list of Entry)

A copy of f with every entry in entries appended, in order. Prefer it to add in a loop: each module call rebuilds the whole Feed.

f
the source feed
entries
the entries to append
Returns Feed
the feed with the entries added

build

jennifer
feed.build(format as string, f as Feed)

Render f to feed XML in the named format: "rss" (RSS 2.0) or "atom" (Atom 1.0). Values are XML-escaped; unset dates are omitted.

format
"rss" or "atom"
f
the feed to render
Returns string
the feed document as XML text
Throws Error
when format is not "rss" or "atom"

entry

jennifer
feed.entry(title as string, link as string)

A new Entry with the given title and link (empty id / summary / content, unset dates).

title
the entry title
link
the entry URL
Returns Entry
the new entry

entryAuthor

jennifer
feed.entryAuthor(e as Entry, author as string)

A copy of e with its author set.

e
the source entry
author
the item author (a name or email)
Returns Entry
the updated entry

entryCategory

jennifer
feed.entryCategory(e as Entry, category as string)

A copy of e with category appended to its category tags.

e
the source entry
category
the category / tag to add
Returns Entry
the entry with the category added

entryContent

jennifer
feed.entryContent(e as Entry, c as string)

A copy of e with its full content set (Atom).

e
the source entry
c
the content text
Returns Entry
the updated entry

entryEnclosure

jennifer
feed.entryEnclosure(
    e as Entry,
    url as string,
    length as int,
    type as string)

A copy of e with a media enclosure set (the podcast / audio / video file).

e
the source entry
url
the media URL
length
the media size in bytes (0 when unknown)
type
the MIME type (e.g. "audio/mpeg")
Returns Entry
the entry with the enclosure set

entryId

jennifer
feed.entryId(e as Entry, id as string)

A copy of e with its stable id set.

e
the source entry
id
the identifier (RSS guid / Atom id)
Returns Entry
the updated entry

entryPublished

jennifer
feed.entryPublished(e as Entry, t as time.Time)

A copy of e with its published instant set.

e
the source entry
t
the first-published instant
Returns Entry
the updated entry

entrySummary

jennifer
feed.entrySummary(e as Entry, s as string)

A copy of e with its summary set.

e
the source entry
s
the summary / description text
Returns Entry
the updated entry

entryUpdated

jennifer
feed.entryUpdated(e as Entry, t as time.Time)

A copy of e with its updated instant set.

e
the source entry
t
the last-updated instant
Returns Entry
the updated entry

feed

jennifer
feed.feed(title as string, link as string)

A new empty Feed with the given title and site link (no entries, unset date).

title
the feed title
link
the feed's site URL
Returns Feed
the new feed

feedAuthor

jennifer
feed.feedAuthor(f as Feed, author as string)

A copy of f with its author set.

f
the source feed
author
the feed author (a name or email)
Returns Feed
the updated feed

feedCategory

jennifer
feed.feedCategory(f as Feed, category as string)

A copy of f with category appended to its category tags.

f
the source feed
category
the category / tag to add
Returns Feed
the feed with the category added

feedUpdated

jennifer
feed.feedUpdated(f as Feed, t as time.Time)

A copy of f with its updated instant set.

f
the source feed
t
the last-updated instant
Returns Feed
the updated feed

hasEnclosure

jennifer
feed.hasEnclosure(e as Entry)

Report whether an entry carries a media enclosure (a non-empty enclosure url).

e
the entry to test
Returns bool
true when the entry has an attached media file

kind

jennifer
feed.kind(text as string)

The feed format of text, by its root element: "rss" or "atom".

text
the feed XML
Returns string
"rss" or "atom"
Throws Error
when the XML is malformed or the root is neither (kind "value")

parse

jennifer
feed.parse(text as string)

Parse feed XML into a Feed, detecting RSS vs Atom from the root element. An absent date is the epoch sentinel; one that is there must parse (RFC 822 for RSS, RFC 3339 for Atom). An Atom type="xhtml" title / summary / content is the markup inside its XHTML <div>.

text
the feed XML (RSS 2.0 or Atom 1.0)
Returns Feed
the parsed feed
Throws Error
kind "value" for a document that is not a well-formed feed (see the module doc); the xml library's error for malformed XML

Structs

Enclosure

A media enclosure attached to an entry: the podcast / audio / video file. Maps to RSS <enclosure url length type> and Atom <link rel="enclosure">. An entry with an empty url has no enclosure (omitted on build).

jennifer
def struct Enclosure {
    url as string,
    length as int,
    type as string
};
url
the media URL
length
the media size in bytes (0 when unknown)
type
the MIME type (e.g. "audio/mpeg")

Entry

One feed item. link is the item URL, id its stable identifier (RSS guid / Atom id), summary a short description (RSS description / Atom summary) and content the full body (Atom content; RSS carries only the one description, mapped to summary). author is the item author, categories its tags, and enclosure an attached media file (podcast episode). An unset date is the Unix epoch.

jennifer
def struct Entry {
    title as string,
    link as string,
    id as string,
    published as time.Time,
    updated as time.Time,
    summary as string,
    content as string,
    author as string,
    categories as list of string,
    enclosure as Enclosure
};
title
the entry title
link
the entry URL
id
the stable identifier (RSS guid / Atom id)
published
the first-published instant (epoch if unset)
updated
the last-updated instant (epoch if unset)
summary
a short summary / description
content
the full content (Atom only)
author
the item author (RSS author / dc:creator, Atom author/name)
categories
the item's category tags
enclosure
an attached media file (empty url = none)

Feed

A syndication feed: channel-level metadata plus its entries.

jennifer
def struct Feed {
    title as string,
    link as string,
    updated as time.Time,
    entries as list of Entry,
    author as string,
    categories as list of string
};
title
the feed title
link
the feed's site URL
updated
the feed's last-build / updated instant (epoch if unset)
entries
the feed items, in document order
author
the feed author (RSS managingEditor, Atom author/name)
categories
the feed's category tags