timpile

timpile

Handwrite - Unofficial API wrapper for Handwrite.io

I started using the Handwrite REST API for a side project and since they don’t have an API library for Elixir I decided to make an unofficial one for them: handwrite | Hex.

This is my first published Hex package and I have only used Elixir for side projects, so I’d love to make this library more stable and usable. I’m sure there is a lot of improve on, so any feedback or code reviews would be greatly appreciated!

First Post!

malloryerik

malloryerik

I checked out handwrite.io because of your library, but I see their pricing policy is “inquire within”. I’m guessing they’ve got reasonable pricing if you’re using it on side projects?

Most Liked

timpile

timpile

I’m still only using it in a sandbox environment, but as far as I can tell the pricing is comparable to other card printing services. They are very responsive, if you reach out to them I’m sure they can give you a better answer.

chulkilee

chulkilee

Welcome! My first hex package was also a rest api wrapper (ex_force) :slight_smile:

Here are some feedback/thoughts:

Dependency

  • Although they are mostly swappable, recent packages chose jason instead of poison for json
  • http client - I’m using tesla whenever possible since users can swap the http library easily.

Handwrite.Client

  • Instead of "#{secret_key()}", you can make sure secret_key returns string value.. which leads to the next point
  • secret_key/0 calls System.get_env/1 on runtime - it may be okay for application (although not recommended), but for library, you should use application configuration (e.g. Application.get_env/3) (for global config) or pass that value down to the function.

Code organization

  • I found you made a module for each resource - such as Handwrite.Endpoint.Handwriting. There is no right answer, but I found it’s actually easier to read, use, and maintain the code I put the all things under one module if they’re at the similar level resources. See ExForce module source.

Last Post!

chulkilee

chulkilee

Oh, I agree with you in that global config for a library must be avoided.

I should have been more clear on this part :man_facepalming: I wanted to give hints to move away from using System.get_env/1 first…

For starter - and this kind of library, this is very likely to have one instance - which is “acceptable” (although I don’t prefer) to have (global) application config. That’s why I refer to the library guides lines, which has a section for Avoid application configuration :slight_smile:


@timpile for the configuration - it’s better to have a library to provide building blocks and let library users load config as needed.

For example:

# in config
config :my_app, :handwrite, url: "https://example.com", api_key: "..."

# in your helper module

defmodule MyApp.Handwrite do
  def client do
    opts = Application.get_env(:my_app, :handwrite)
   Handwrite.client(Keyword.fetch!(opts, :url), Keyword.fetch!(opts, :api_key)
  end
end

# then you use it like this

MyApp.Handwrite.client()
|> Handwrite.create_whatever(my_opts)

By doing this, your library does not care how to store and retrieve the configuration at all - and that is in the library user code.


I did make a mistake when I wrote the first library - I had default config value and make authentication happens when not passed to make it easy to use.. but I found it’s not good. See my commit to change from httpoison to tesla with 1) dropping default config and 2) making all functions to take a tesla struct, which holds the all information such as url and auth token - see Replace HTTPoison with Tesla · chulkilee/ex_force@8d32d9a · GitHub

Where Next?

Trending in Announcing Top

anuaralfetahe
Hello Published a new library - ProcessHub! ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
aseigo
ICal is a library for interacting with iCalendar data. It parses iCalendars into typed Elixir structs via ICal.from_ics, and can prepare ...
New
GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
patrols
CDPEx is a Chrome DevTools Protocol client for Elixir. It drives a real Chrome straight over CDP, with no ChromeDriver, Selenium, or WebD...
New
roeland
I built this for https://app.masterleague.nz, a small pickleball league site of mine, and figured it might be useful to others: AddToCale...
New
kip
I’ve published localize_mcp, a Model Context Protocol server for the Localize library. This is the last piece of the family before 1.0 r...
New
Semurg
Hi all, long-time reader, finally made an account. I wanted to introduce something my team and I have been building, mostly because the ...
New

Other Trending Topics Top

stefanchrobot
Hi, I need a way to handle data migrations in my application. I found an article by @wojtekmach about manual migrations: Automatic and ma...
New
PragmaticBookshelf
Bruce A. Tate @redrapids and Sophie DeBenedetto @SophieDeBenedetto edited by Jacquelyn Carter @jkcarter The days of the traditional requ...
New
mudasobwa
I’m glad to introduce Estructura, the library that equips structs with Access, Enumerable, and Collectable implementations, as well as pe...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
garrison
For those who are not aware, “AI agents” are, for the most part, commodity LLMs which are given access to “tools” and prompted to complet...
#ai
New
jola
I’ve been bumping into some rough edges recently with Elixir dependencies that use app config and start their own supervision trees and I...
New

We're in Beta

About us Mission Statement