UlrikHD

UlrikHD

Any tips on implenting the lemmy api?

I’ve been wanting to write a library for the lemmy API so that I can port some of my scripts over to elixir. For those unfamiliar with lemmy, it’s a FOSS project trying to mimic reddit.

Since I’ve only used elixir for a single project/5 months, I’d like to know if my idea for the library structure is sound.

My current plan is to use req as a dependency to take care of the network of communication. I’m leaning towards using a GenServer process to store the JSON Web Token for an account login, and then have all API calls on the format api_call(GenServer_PID, api_params...). The api_call will then make a GenServer call to retrieve the JWT before sending the request.

The advantage of this format is that you can easily juggle multiple accounts/processes in the same VM process if you want to wrap up and supervise multiple scripts in one process. The disadvantage is that all calls have to go through the GenServer process to retrieve the JWT, though I don’t think this is a realistic bottleneck.

I suppose my questions are:

  1. Does it make sense to use a GenServer to simply store and potentially update the session token of an account.
  2. Is there a different approach/convention that is typically used when implementing REST APIs in Elixir?
  3. Are there any pitfalls I should be aware while writing the library?

First Post!

dimitarvp

dimitarvp

Why not use ETS with read concurrency?

Most Liked

dimitarvp

dimitarvp

The BEAM VM has zero sandboxing abilities. One process running malicious code can extract a lot of information. It’s best that you don’t concern yourself with this; assume the code in your application is safe and do worry only about interacting with the external world. Using a secrets manager to inject the values that your application needs is also pretty much the accepted approach for years now.

Last Post!

dimitarvp

dimitarvp

RE:GenServer or not, I don’t base my API usage decisions on anticipated usage patterns; despite the huge skepticism of many, these usage patterns do change even in mature production codebases and then you’re left holding the bag.

So I wouldn’t use GenServer. Don’t use OTP mechanics unless you really have to.

Where Next?

Popular in RFCs Top

KristerV
How I currently use Hexdocs I use hexdocs all day every day, but finding the right module and function takes too long even with my bookma...
New
benlime
In the last couple of days I was playing around with LiveView, function components and animations. I ended up with a little prototype whi...
New
weakwire
Hello people, Big fan of elixir & phoenix LiveView. While designing LiveView applications I use LiveComponent extensively. Issue-I...
New
brettbeatty
At my work we build a lot of mix tasks for backfills and other maintenance tasks. Even with OptionParser we seem to copy a lot of boilerp...
New
noizu
Hello, I wrote a more comprehensive llama_cpp nif wrapper noizu-labs-ml/ex_llama: (github.com) inspired by the unfortunately doa jereg...
New
simulacre7
Hi everyone, I’m building Aethrion, an early alpha Elixir runtime for persistent AI characters. Repo: GitHub - simulacre7/aethrion: A s...
New
bartblast
:test_tube: Could use a hand testing something. Just landed a protocol pruning enhancement - the compiler now drops protocol implementati...
New

Other popular topics Top

New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
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
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement