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 customise the options to the Plug.Parsers JSON decoder?

With Plug.Parsers, it is possible to configure the module that is used to parse JSON requests: plug Plug.Parsers, parsers: [:json], json_decoder: Jason However, with this syntax Jason.decode!/2 is called with an empty opts parameter. How can we…
Adam Millerchip
  • 20,844
  • 5
  • 51
  • 74
0
votes
1 answer

Body of post request not sending correctly

I am writing a POST request that should send some information to a REST api using elixir, this information should be able to be accessed in the conn.body_params, however it appears empty. My code is as follows: conn2 = conn(:post,…
George Francis
  • 462
  • 2
  • 7
  • 16
0
votes
1 answer

Can't load images users uploaded with arc on prod on heroku

I use arc to save users uploads and add to the db. On localhost everything works fine with (in lib/app_web/endpoint.ex) plug Plug.Static, at: "/uploads", from: Path.expand("./uploads"), gzip: false I can't understand where I can save uploads on…
0
votes
0 answers

Plug causing memory leak

We have an elixir (version 1.8.1) web application running inside docker (Server version 1.12.6, Client version 18.09.2) containers within a rancher cluster (Running within EC2, using the AMI Rancheros 1.4.0). We are using the phoenix framework…
Sgoettschkes
  • 13,141
  • 5
  • 60
  • 78
0
votes
1 answer

How do I call the route defined by the Plug.Router macro at runtime?

Can I manually build a conn and then call them like a function? If you don't understand what "them" means, look at the code below. For example, define a route /ping get "/ping" do send_resp(conn, 200, "pong") end I know that it can be done with…
Hentioe
  • 228
  • 1
  • 9
0
votes
1 answer

Dilemma: should I use a module plug or function plug: Phoenix

I need to reuse a function plug on different modules but it seems a bit redundant to do that. Is a module plug a better way to do this or how can I reuse the function plug?
0
votes
1 answer

Forward args from custom plug to second plug

I have a custom plug that looks like this: defmodule Db.Auth.GuardianPipeline do use Guardian.Plug.Pipeline, otp_app: :db, module: Db.Auth.Guardian plug Guardian.Plug.VerifySession, claims: %{"typ" => "access"} plug…
steventnorris
  • 5,656
  • 23
  • 93
  • 174
0
votes
1 answer

Forward options from a Plug.Router to another Plug.Router

Background I have a Plug.Router application that receives some options. I need to pass these options to other plugs via forward but I don't know how to do it. Code This is the main router. It receives requests and decides where to forward them.…
Flame_Phoenix
  • 16,489
  • 37
  • 131
  • 266
0
votes
1 answer

Handling error for large queries and sending 413 response

I have a voice note upload function. I was writing tests and as part of it I wrote the following test for larger files where I want to have it throw a 413 Entity too large error: test "send VN fail when too large", %{conn: conn} do …
Omar Hussein
  • 1,057
  • 2
  • 13
  • 31
0
votes
1 answer

POST request made to Plug router with HTTPoison fails

I'm trying to make a POST request to a Plug router using HTTPoison. My GET requests are successful, it is only the POST that is failing. I'm not sure if the problem is Plug or HTTPoison: # server.ex defmodule MyServer do use Application use…
dopatraman
  • 13,416
  • 29
  • 90
  • 154
0
votes
1 answer

Elixir with Plug and Cowboy: Disable nice error messages

I am using heroku-buildpack-elixir to deploy an application to Heroku. My application consists of a simple Plug/Cowboy setup. I noticed that when unhandled exceptions occur, a nice error message appears, showing the stack trace and the lines of code…
Raphael Müller
  • 971
  • 2
  • 8
  • 20
0
votes
0 answers

Android studio 3.1.3 download kotlin-plug fail

enter image description here Android studio 3.1.3 use kotlin-plug v'1.2.60, always Connection refused: connect. What is the problem and how can I solve it?
jake
  • 1
  • 1
0
votes
1 answer

How to test controller methods that use HEAD in Phoenix

Currently the documentation is clear and vibrant with the common HTTP verbs, but we started implementing some HEAD routes today and it is not tested the same way as the others. To test say a GET method: conn = get conn, controller_path(conn,…
Eric Stermer
  • 959
  • 1
  • 12
  • 23
0
votes
2 answers

Elixir Pass parameter into Plug for previous plug parameter

This may not be a Breadcrumble question, but how do I pass a parameter from a previous plug into the breadcrumbable? For example, if the previous plug set_merchant sets the merchant on conn.params.merchant, how can I pass that id to breadcrumable? …
DogEatDog
  • 2,899
  • 2
  • 36
  • 65
0
votes
1 answer

Why is Java plug in being deprecated

As per the Java 9 specifications, Java plug in is being deprecated. A well known reason behind this is the removal of plug in support entirely by the popular web browsers. Is there any other reason why this step is being taken? I had read in one of…
Curious Coder
  • 646
  • 8
  • 18