Morzaram

Morzaram

REST API structure at a medium sized project?

Hey everyone I was wondering what does your basic REST API controllers look like?

I miss the rails way of

  • dry.rb based form validation object
  • using AR directly in the controller for saving
  • rendering response

Instead of the current elixir way:

  • create make a changeset in the schema
  • make an update function in the context for that particular controller method
  • connect the schema to the new function in the context
  • use the context to validate, update and save

How do you all do it? It feels like a lot of extra steps and a lot more functions that rely on each other.

Also with this pattern, I’m wondering how this would work at scale. I’m already feeling the chaos between polymorphism, 3 features, and 5 different background jobs working around polymorphism.

I noticed that theres the (drops)[Elixir Drops 💦 — drops v0.2.1] library which feels like dry.rb which is nice, but something feels off on how to manage context, schemas, etc at scale.

Would love to hear some ideas on how y’all manage this. I’m missing rails a little bit in this aspect, not going to lie.

I know I should ‘stop thinking OOP’ and think that it’s all functions but it feels so abstract. I need a way to organize the functions and the default way feels quite overwhelming. I’ve read the DDD book but this paradigm coding and organization feels like I’m spinning a web of complexity (even though this feels right).

Anyways I know this is a bit of a rant but I’m getting concerned of the future of expanding this project that is slowly growing more and more into something that feels unmanageable.

Any advice?
How do you all manage complexity and things like these?

Still feel so new even though I’ve been writing elixir for a few years now…

Thanks,

Most Liked

krasenyp

krasenyp

The question is not really about the interface. There are a myriad guides on how to structure a web project in Elixir and Phoenix.

As for REST, I usually decide what hypermedia formats I’m going to support. Is it HAL, JSONAPI, Siren, or something else? Then I implement my business logic as a library.

Where Next?

Popular in Questions Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36820 110
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 55125 245
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49266 226
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement