How would you do this the "Elixir Way?"

Like a recent previous poster, I like to write API clients. (because I consume a lot of APIs)

I have one I use a lot, written in PHP, and I’m trying to rewrite it in Elixir to help me learn. I am very new to Elixir and have only read the Introduction to Elixir book.

My question is this:

As a user of Elixir, how would you expect to interact with an API client like this?

This is a contrived example of how it is done in my PHP library:


$hubspot = new Hubspot($config);

# Use API client to get all contacts
$response = $hubspot->contacts()->all();

foreach ($response->contacts as $contact) {
    # Use API client to update contact, changing all firstnames to Joe
    $hubspot->contacts()->update($contact->vid, [
            'name' => 'firstname',
            'value' => 'Joe'

Using that example, is there an easy comparison?


Here’s an example of pulling some records from AWS’s DynamoDB, and updating each.

|>"users", %{&1 | name: "Joe"} ))

One issue with direct comparisons like this though is that I don’t know enough about what’s implied by updating each contact in your case to know at what level of abstraction we’re working. For example, you’ll notice that I explicitly have to mention the users table that we’re using from Dynamo. However I could also wrap that inside some User module, and abstract away explicit ExAws calls so that it looked more like

|>, name: "Joe"))
|> DB.perform

There are endless possibilities.



For my example, all the update really does is send an HTTP request using another HTTP client library behind the scenes and returns the response:

1 Like

So you need example of usage http client.
You can check: