D4no0
Getting data from Rest API in Liveview project
At the moment I have an API that returns json responses, the api is used for a mobile application. The next step is to create a web frontend and the choice we ended up using is LiveView.
From what I understand I have a few approaches how I can get the required data:
- Reimplement the logic from Rest API controllers.
- Use the REST API controllers and decode the json response.
Is there a cleaner way to do this? I would like to use the controllers, without having to encode an decode jsons everytime
Most Liked
PJUllrich
Are you serving the API with a Elixir + Phoenix backend? If yes you could extract the data-gathering functionality from your controllers into another module and use the same functions from both your controller and your LiveView.
dimitarvp
Same advice applies: extract that auth logic outside of the plugs and use them there and in your LiveView code.![]()
D4no0
Yes, I have an umbrella project that contains these projects.
The problem with extracting the logic is that I have plug guards for authentication and roles checking on specific endpoints, I would like to avoid duplicating them, since at some point somebody might make a mistake and mess up roles on specific endpoints.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #code-sync
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








