Questions tagged [plug]

Plug is a web application framework for Elixir.

An example of a Plug from the module documentation:

Hello World

defmodule MyPlug do
  import Plug.Conn

  def init(options) do
    # initialize options
    options
  end

  def call(conn, _opts) do
    conn
    |> put_resp_content_type("text/plain")
    |> send_resp(200, "Hello world")
  end
end

The snippet above shows a very simple example on how to use Plug. Save that snippet to a file and run it inside the plug application with:

iex -S mix
iex> c "path/to/file.ex"
[MyPlug]
iex> {:ok, _} = Plug.Cowboy.http MyPlug, []
{:ok, #PID<...>}
101 questions
0
votes
1 answer

How to represent C2D message in IoT Plug & Play DTDL definition

I'd like to know how to represent C2D message and External message on IoT Edge module by IoT Plug & Play DTDL definition. I thought that a Command with a value of "asynchronous" in commandType property is used as C2D message. But when I check the…
0
votes
0 answers

"Phoenix.Router.NoRouteError" when attempting to access uploaded image file in sub directory of Phoenix application

Phoenix/Elixir learner here :) I tried to access an image file under sub directory (ie:dashboard) of a Phoenix application, something like : http://localhost:8000/dashboard/media/tv1_1.jpg but it keeps throwing me with the same error…
dewa19
  • 1
  • 2
0
votes
1 answer

No function clause matching in Access.get/3

In my free time I am learning elixir, and now I am trying to develop simple Elixir API. Everything works fine, besides when I try to insert new values using Postman/curl. When I'm trying to do so with such data: { "tree": "nil", "value":…
Kapeusz
  • 61
  • 7
0
votes
0 answers

How to create a keep-alive API endpoint with Cowboy in Elixir?

Note: I am new to elixir and the forum, and hence my question might be missing some details. Do let me know if additional information is required from my end. I am trying to integrate the trading view’s /streaming endpoint. A snippet of what it says…
0
votes
1 answer

Is there a way to get the modified data from within a EEx template

I'm using EEx template engine to render HTML pages (no Phoenix here). I'm passing the connection (Plug.Conn) conn to the template along with extracted parameter list (params) and the session map (session) with : body = EEx.eval_file(path, conn:…
mszmurlo
  • 1,250
  • 1
  • 13
  • 28
0
votes
1 answer

Is there a way to keep GenServer state persistent?

I am trying to implement a counter using GenServer. The idea is to increment a counter whenever a client visits the server, and print it in the console. However, after every visit GenServer state reset or PID terminated. Is there a way to keep…
GaB
  • 1
  • 3
0
votes
1 answer

getLibraryDirectory not working for desktop app

i'm working on Flutter desktop application and got stuck at a point. I want to create local database for data storage. I'm using path_provider plugin to get path of directory for saving database file. the function getLibraryDirectory() not working…
Dev94
  • 757
  • 6
  • 24
0
votes
1 answer

elixir phoenix - put_flash/3 in the plug

I created a plug to check if the user already created a profile, and redirect them to the /profiles/new page with a flash if they not yet have one: Plug.CheckProfile case profiles do nil -> conn |> put_flash(:info, "No profile found.") |>…
sooon
  • 4,718
  • 8
  • 63
  • 116
0
votes
2 answers

How to fix Flutter doctor android studio plugin(Dart , Flutter) issue?

I installed the latest version of the Android Studio(4.1.1), the latest version of Flutter (Flutter 1.22.4 • channel stable). I installed the Dart & Flutter plugin in Android Studio. But the flutter doctor gives the plug-in is not installed…
0
votes
1 answer

Elixir Plug: Return redirect 302

I've inherited a project written in Elixir. Basically it's a API gateway. In this case, I need to perform a redirect from my API Gateway URL to the one which the destination URL redirects to. So the situation is like this. Request to (API Gateway in…
alex89x
  • 479
  • 4
  • 14
0
votes
1 answer

Prevent Plug.ErrorHandler from re-raising error after callback

Background I have a simple Plug router with a PUT endpoint that receives a JSON body. To parse it I am using Plug.Parsers. Problem The Plug.Parsers plug works fine and puts the json inside conn.body_params. However, if the JSON I am receiving is…
Flame_Phoenix
  • 16,489
  • 37
  • 131
  • 266
0
votes
1 answer

Running a plug pipeline after request is processed

Plugs pipelines are an amazing way to build applications. Currently though I've only been applying pipelines to filter/format data before the request hits the controller. Is there a way to apply a pipeline to run after every view is processed? I…
ThreeAccents
  • 1,822
  • 2
  • 13
  • 24
0
votes
1 answer

Download failes for chuncked file in browser Elixir

Apparently it looks like I am missing something to add in my code. I am sending a chunked HTTP response and with content type text/csv so that if I open it in the browser it should download. But it fails to download and I have no idea about its…
0
votes
1 answer

What is the best way to enable development hot reloading when not using pheonix?

So I'm learning Elixir and Pheonix looked too much to start learning, so I make a simple JSON Rest API with Plug and Poison, but to see any changes I need to stop the server and run mix run --no-halt again. I came from nodeJS and it has nodemon that…
0
votes
1 answer

Roles plug inside of router phoenix

At the moment I have a roles plug, that looks the following: plug Roles, :role It receives as the second parameter the specific role and the current user is obtained from the current token that is in use. I am using the plug inside of the…
Daniel
  • 2,320
  • 1
  • 14
  • 27