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

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
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
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement