#Modeling external service payloads

8 messages ยท Page 1 of 1 (latest)

median flame
#

๐Ÿ‘‹ I'm brand new to Elixir coming mostly from Python and I'm experiencing some analysis paralysis when it comes to data deserialization options.
I'm writing a small Phoenix project that doesn't need a database. I basically call a bunch of external APIs and display the results. When it comes to modeling the responses of the external APIs, do I:

For other former Python-ers, if this were Python, I'd use dataclasses or maybe Pydantic to do this. What seems like the "best" or at least "a good" option with Elixir? It seems I have a lot of them.

#

Also, maybe some important context that while this is a personal project, I'd like to practice some amount of "how would I do this on a real project"

sinful lark
#

structs is a good starting point

#

if you need to perform significant validations on the contents of the structs, upgrade to Ecto embedded schemas

#

As a former pythoner, I started with option 1, maps everywhere and I've since been refactoring as time allows

median flame
#

if you need to perform significant validations on the contents of the structs

Yeah, for now I don't. I just want some general type-hinting, static type checking, and maybe some coercion, e.g. datetime strings to DateTimes

barren island
#

ecto will give you the coercion, whereas with plain structs you'd have to do that yourself. Personally I would (and have) use ecto.

pallid portal
#

Coming from python/django I had a hard time wrapping my head around the fact that Ecto is much more than just a database interface. Between embedded schemas and schema-less changesets, it's more like django's ORM and Forms in one, but with a much nicer (imo) interface. So I would use embedded schemas (which are really just table-less schemas) or structs, and leverage Ecto for validation. Just don't define a Repo.