How to Render RSS Feeds in Elixir Phoenix: Difference between revisions

From ElixirBlocks
Jump to: navigation, search
(Created page with "This is an example of how to capture and display an RSS feed in Phoenix. You must first install the '''Feedex''' RSS package. * https://www.hex.pm/packages/feedex * https://hexdocs.pm/feedex/Feedex.html * https://github.com/diegocurbelo/feedex Below is a LiveView example that uses the above package to render contents of an RSS feed to the browser. The raw() method comes with Elixir Phoenix and is used to sanitize HTML. ==Example== <source> defmodule AppWeb.PageLi...")
 
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
This is an example of how to capture and display an RSS feed in Phoenix.
This is an example of how to capture and display an RSS feed in Phoenix.


You must first install the '''Feedex''' RSS package.
<hr/>
 
{{Liveview basics required}}
 
<hr/>
 
To use this example you must first install the '''Feedex''' RSS package.


* https://www.hex.pm/packages/feedex
* https://hexdocs.pm/feedex/Feedex.html
* https://github.com/diegocurbelo/feedex
* https://github.com/diegocurbelo/feedex


Below is a LiveView example that uses the above package to render contents of an RSS feed to the browser.
Below is a LiveView example that uses the above package to render contents of an RSS feed to the browser.


The raw() method comes with Elixir Phoenix and is used to sanitize HTML.  
The raw() method comes bundled with Elixir Phoenix and is used to sanitize HTML.  


==Example==
==Example==

Latest revision as of 19:16, 5 December 2023

This is an example of how to capture and display an RSS feed in Phoenix.


This document assumes that you understand the basics of Liveview. This includes:


To use this example you must first install the Feedex RSS package.

Below is a LiveView example that uses the above package to render contents of an RSS feed to the browser.

The raw() method comes bundled with Elixir Phoenix and is used to sanitize HTML.

Example


defmodule AppWeb.PageLive do
  use AppWeb, :live_view

  def mount(_params, _sesion, socket) do
    {:ok, socket}
  end

  def render(assigns) do
    {:ok, feed} = Feedex.fetch_and_parse("https://podcastfeeds.nbcnews.com/RPWEjhKq")

    [head | tail] = feed.entries
    IO.inspect(head.content)

    ~H"""
    <%= raw(head.content) %>
    """
  end
end