It turns out that implementing HTTP Basic Authentication in your Phoenix app is easy when you use plugs. Let’s first see how the plug itself works:
This method of adding a Plug means that we add the Plug functionality inside a self-contained module.
When the plug gets called, we’ll receive a username and password from our app’s configuration, which represents the correct auth details. (We’ll see how this works later.)
If this is the first time the browser requests a resource that uses this Plug, it won’t be sending any attemped auth details yet, because the browser hasn’t yet…
Many developers store images in Amazon S3, a Git repo, or in a filesystem. I’m storing mine directly in my PostgreSQL database. As it turns out, that’s the ideal approach to the problem I’m solving…
In the examples below, we’ll be working with an existing Ecto model called
Recommendation, which already contains a URL to an image we’d like to fetch and store in our database. To do this, the first step is to add a binary field to the DB schema.
First, generate a new migration to a field to a table:
> mix ecto.gen.migration add_image_binary_to_recommendations
Then, we need…
Software engineer. Elixir/Phoenix. Ruby/Rails. Television enthusiast. BBQ connoisseur.