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

WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
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
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
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
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New

Other popular topics Top

lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
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 48342 226
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement