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

alisinabh
Hey everyone i’ve developed a library for Jalaali calendar for elixir which supports converting Gregorian dates to Jalaali and vice vers...
New
pkrawat1
Hey guyz We at @aviabird are working on a payment library in elixir/phoenix. We are targeting March 2018 to add 56 Gateways to it. Have...
New
anshuman23
Hello all, I have been working on my proposed project called Tensorflex as part of Google Summer of Code 2018.. Tensorflex can be used f...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 30486 241
New
oltarasenko
Dear Elixir community, After a year of development, bug fixes, and improvements, we are proudly ready to share the release of Crawly 0.1...
New
tmbb
PhoenixWS - Websockets over Phoenix Channels Source code on Github here: GitHub - tmbb/phoenix_ws: Websockets implemented over Phoenix Ch...
New
markmark206
simple_feature_flags is a tiny package that lets you turn features on or off based on which environment (e.g. localhost, staging, product...
New

Other popular topics Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
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
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
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42716 114
New

We're in Beta

About us Mission Statement