An Elixir/Phoenix application with LiveView that allows users to test and preview an Open Graph image from any given URL.
The following steps assume a prior installation and setup of Elixir and Postgres. This project uses elixir 1.14.2-otp-25
, erlang 25.2
, and postgres 14.8
.
- Clone the repo, e.g.
git clone git@github.com:aimeebooth/og_previewer.git
- Change directories -
cd og_previewer
- Setup a local database -
mix ecto.create
- Run the app locally -
mix phx.server
oriex -S mix phx.server
OG Previewer is a LiveView application that sends a user-submitted URL to an async task and reports the result back to a LiveView via Phoenix.PubSub. The LiveView handles the url processing state and conditionally updates the client over the socket connection. The first iteration of this solution used Oban to create a background job for the processing and stored the state in the database. The choice for Oban was made largely due to this issue with HTTPoison#get/1 because I wanted a way to automatically retry requests. However, when I added an async handler for PubSub broadcasting the result to the LiveView, I realized allowing the LiveView to handle the processing state was a better solution and removed Oban. The one trade-off with allowing LV to handle state is that it's so fast, the processing
state is barely visible in the browser before it updates and displays the image :)
An example 200 request can be seen with J. Robert Oppenheimer on Wikipedia. An example of 308 handling can be seen with ConAir on IMDB.
- Handle edge case seen with some Open Graph-compliant URLs
- Add CSS