themgt

themgt

Experimental Shopify API client, feedback wanted

Longtime rubyist, I’m very new to Elixir and have been looking for projects to experiment on. Our company does a fair amount of work building app integrations on the Shopify platform, and when we want to scaffold out REST API clients in ruby we often use a fairly simple metaprogramming pattern, which works best on APIs that have relatively uniform naming / return values.

As an experiment I tried to sort of port this metaprogramming idea to an Elixir Shopify API client (the only existing one I could find is boulevard/shopify and lacks most of the endpoints). The library I built is here: GitHub - themgt/shopify: Experimental Elixir Shopify API Client · GitHub

I’m still just starting to wrap my head around Elixir metaprogramming, but you can see in the quite brief code it basically loops through all the first-level Shopify API endpoints and defines CRUD methods for accessing them and returning the JSON data.

I was mainly looking for some comments / examples of best practices for REST API clients in Elixir. I’m assuming I should use {:ok, _} vs {:error, _} return signatures?

Coming from ruby I find it a bit awkward passing around the struct with domain/token - any way around that, or should I change the arity so that’s first in all the methods?

Also just curious in general on the Elixir community’s thoughts on using metaprogramming in a situation like this - a lot of the documentation has a big flashing “only if you need it!” warning - wondering if it’s generally frowned upon?

First Post!

OvermindDL1

OvermindDL1

I don’t know shopify at all so just a couple of things from me. :slight_smile:

For functions, yes. If an error condition is possible (like remote server calls possibly failing) then error and ok tuples like you have there are perfect. You should not raise exceptions except in truly exceptional circumstances (they are slow, and bad form).

If it is designed to work with Plug and/or Phoenix, the usual way is to add it to the Conn structure as an assign somewhere earlier in your pipeline. If you get it during your main require you might want to factor it out higher in the pipeline so it becomes easier to handle and embed elsewhere too. Otherwise not really, you gotta pass around something. That is the usual functional programming. :slight_smile:

Only if it truly makes the interface better, shorter, more readable, and not magical; magical looking code that you cannot figure out what it is doing from looking at it is bad. Otherwise raw functions are almost always better.

Where Next?

Popular in Announcing Top

danschultzer
In short Plug n’ play OAuth 2.0 provider library. Just set up a resource owner schema with Ecto (your user schema), install the dependen...
New
treble37
Just looking for a little feedback on a tiny helper library I built - Sometimes I find the need to convert maps with atom keys to maps w...
New
versilov
Could not wait for the missing Elixir ML libraries to appear, so, I wrote one myself, taking https://github.com/sdwolfz/exlearn as a foun...
New
tmbb
I’ve been working on two packages (not on hex.pm yet) to build admin interfaces for phoenix apps: bureaucrat - which contains a bunch ...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44778 311
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44265 214
New
Flo0807
Hello everyone! I am excited to share our heart project Backpex with you. After building several Phoenix applications, we realized that...
New

Other popular topics Top

dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
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
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44265 214
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

We're in Beta

About us Mission Statement