3 ms·
People using Phoenix Liveview -- how do you serve native apps relying on the same backend?
by oDot 4y ago
People using Phoenix Liveview -- how do you serve native apps relying on the same backend?
- sodapopcan 4y agoAs it stands you have to write a separate API, though there is work being done on native [0]. Otherwise, part of the initial value-prop of LiveView is that if you don't need multiple frontends and you don't need offline support--which a whole lot of apps don't--then LiveView drastically simplifies your stack while still delivering "SPA-like" speed. [0] https://native.live/ https://native.live/
- a_bored_husky 4y agoYou would need to write the REST/GraphQL API. Maybe with help from Ash Framework (https://ash-hq.org https://ash-hq.org) to make it easier to reuse logic.
- sergiotapia 4y agoI use Absinthe to expose a graphql API endpoint. The Absinthe resolvers just call the contexts/functions my liveviews call anyways.
- Alacart 4y agolike others have said, you'd probably write a JSON API separately. One thing I'll mention though, is that the conventional design of Phoenix to use context modules often makes that very easy, in that your liveviews and API can just call the same business logic functions to crud resources.
- di4na 4y agoThis. As long as you keep the API relatively simple, something like basic CRUD "restful", it is really low cost to transform your domain model modules (regularly called "Context" in the community) into whatever JSON you need. It is just two different presentation of the same data, so you do the work on the data model and the way to access it in elixir, then you just thinly wrap it in the API for it.