phoebe

phoebe

Guides to making a library to wrap an API

Hi, I would like to learn more about Elixir and thought creating a hex library might help me achieve this. I would like to wrap a third-party event/ticketing API that I am using for one of my current projects and then publish this to hex.

I have found an Elixir library for meetup.com’s API, and was thinking of using that as a base. Is that a good start? Are there any really good libraries out there that I could follow for wrapping APIs? Any Elixir patterns I should follow as well?

Btw, I am new to writing any library in any language, so trying to learn as much as I can and also contribute back to the ecosystem.

Thanks!

Most Liked

MrDoops

MrDoops

A good place to start is playing with a library like Tesla or HTTPoison. Those libraries provide a simplified interface around more lower level HTTP clients like Hackney or Mint. You’ll probably need a way to configure authentication; ideally through function parameters or options. Tesla has a decent solution to build an authenticated client at run-time which is helpful to avoid imposing configuration methods on your users.

There are 4 main components to think about with a REST API wrapper:

  • The External Service who’s API you’re wrapping, how to authenticate with it, and what requests and responses can be made.
  • The Consumer of your library (e.g. the Business Logic), what it cares about, and the minimal set of knowledge it should have about how to interact with the service.
  • Your API Wrapper library, how it’s configured, how it authenticates with the External Service, how it validates incoming commands, and how it handles responses from the service.
  • The HTTP Client (e.g. Hackney/Mint) that does the actual work of executing an HTTP Request through the network stack.

The most important part is providing a clean interface between your business logic (consumer of the API Wrapper) to hide implementation details like HTTP request/response. Outside of that you’ll probably want to spend time thinking about how to configure your library.

These resources are worth looking at for Library configuration in general:

Hope this helps!

phoebe

phoebe

Thanks, I got a lot to learn!

Where Next?

Popular in Questions Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
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
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
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 record...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New

We're in Beta

About us Mission Statement