Useful Patterns to communicate with external services

Communicating with external services like a third-party API REST is hard, not only because the contract is designed by someone else. Also, now you need to consider the Fallacies of Distributed Systems. Calls to external services can fail for multiple reasons unrelated to business concerns. You can receive a timeout error, the network can fail, bandwith related errors, etc. However, some patterns exist to build more reliable systems when dealing with network calls....

enero 3, 2023 · Me

How to manage business logic in rails

One of the main problems, when an application grows, is how to keep organized the business logic. Following the “rails way” can conduce to a common result called obese models & obese controllers. This means that your models and your controllers keep growing when you continuously add the business logic in the same place. Another inconvenience is that you are coupling your use cases or business logic to the infrastructure (the framework, the database, and the input interface)....

octubre 25, 2022 · Me

Testing the Phoenix controllers without rebinding the conn

Maybe, for readability purposes, you prefer to avoid variable rebinding. For example, take this generated test code from mix phx.gen.auth task: test "renders log in page", %{conn: conn} do conn = get(conn, Routes.user_session_path(conn, :new)) response = html_response(conn, 200) assert response =~ "Log in" assert response =~ "Register</a>" assert response =~ "Forgot password?</a>" end It’s completely ok. But, you can prefer something like this: test "renders log in page", %{conn: conn} do response = conn |> get(Routes....

mayo 11, 2022 · Me

How to build a flexible API client in Elixir

Normally, to talk with an external API we will search some library to do the work for us. Sometimes, this search is infructuous for some of the next reasons: Exist one or more libraries but are unmaintained. There is no library at all. Existing libraries do not fit our requirements. At this point, you could take the following paths. 1 Build a service module in your app Maybe you just need to consume some endpoints and already use some HTTP client like Tesla....

enero 19, 2022 · Me

Procesando archivos de forma asíncrona con Elixir

Escenario A veces, no todo es un escenario perfecto y puede que para alimentar de información tu aplicación necesitas; no conectarte a una API, si no subir archivos CSV’s. Si es el caso, no quieres que quien sea responsable de esta tarea tenga que subir de 100 en 100 registros por que si sube un archivo con 101, el servidor tarda demasiado en responder, el navegador muestra un error de timeout y la carga se interrumpe....

julio 14, 2020 · Me