Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop support for local middleware/adapter functions #171

Closed
6 tasks done
teamon opened this issue Feb 15, 2018 · 2 comments
Closed
6 tasks done

Drop support for local middleware/adapter functions #171

teamon opened this issue Feb 15, 2018 · 2 comments

Comments

@teamon
Copy link
Member

teamon commented Feb 15, 2018

TODO

  • Remove support for local middleware
  • Remove support for local adapter
  • Keep support for anon fun adapter
  • Remove all references in docs (plug)
  • Add info to migration guide
  • Add test to migration test

Context

What is local middleware?

defmodule Client do
  use Tesla
  plug :some_local_function

  def some_local_function(env, next) do
    # ...
  end
end

Pros

  • No need to create a separate module for something trivial

Cons

  • Additional complexity
  • Conflicting API with now-removed aliases support
  • The function must be public anyway

The local middleware can be replaced with simply module:

defmodule Client do
  defmodule LocalMiddleware do
    def call(env, next, _opts) do
      # ...
    end
  end

  use Tesla
  plug LocalMiddleware
end

Question

Is local function middleware widely used or not?

/cc @amatalai @hodak @any-other-tesla-user

@teamon teamon added this to the 1.0 milestone Feb 15, 2018
@amatalai
Copy link
Collaborator

I have 3 custom middlewares in current project and I never considered using local middleware. Simply because writing defmodule isn't tremendous amount of work and it's easier to reuse them later.

btw, have local middleware been documented anywhere?

@teamon
Copy link
Member Author

teamon commented Feb 15, 2018

That's a good sign!

Unfortunately yes - https://hexdocs.pm/tesla/Tesla.Builder.html#plug/2 (and adapter too)

@teamon teamon changed the title Drop support for local middleware functions Drop support for local middleware/adapter functions Feb 16, 2018
@teamon teamon closed this as completed Feb 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants