anthonator

anthonator

Accent - Plug for converting JSON API keys to different cases

Hey everyone,

I published a new package yesterday that allows a client to request the case it prefers to see the keys of a JSON response in. For example, a JavaScript client may prefer a JSON response to be in pascalCase.

The main goal of the project was to provide the client the ability to make the choice of which case they prefer rather than hard coding a snake_case to pascalCase (or whatever) conversion.

By default, a client can send an Accent header to the server with the case they prefer. Out of the box, we support pascal, camel and snake as options. Both the header used and the supported cases can be customized.

Conversion works both ways. A client can request a response be formatted with a specific case and the server can convert an incoming request to a specific case as well.

Would love to hear your thoughts!

Hex: accent | Hex
Documentation: API Reference — accent v1.1.1

First Post!

OvermindDL1

OvermindDL1

Huh, very use-case specific but very cool!

I’m guessing they did not want to use the GraphQL protocol or so? ^.^

A couple notes if you are curious, Elixir has snake_case / camelCase / UpperCamelCase conversion functions somewhere as I recall, can use those instead of duplicating the work as they are very well tested (since they are used in codegen). Also could add docs on the main README.md on example usage of :supported_cases. :slight_smile:

Looks well written. :slight_smile:

Most Liked

anthonator

anthonator

Thanks for the feedback!

I’m surprised you think that the use-case is very specific. We have a lot of clients for the web services we create that prefer either pascal or camel case. I think most companies use a RESTful API as opposed to GraphQL. Glad to hear your thoughts though!

I didn’t use Elixir’s implementation because they are not Unicode compliant. They only support ASCII. They say so as much in the Macro docs.

Thanks for the documentation suggestion! I’ll definitely do that.

Thanks again! I really appreciate the time you took take a look! :smile:

OvermindDL1

OvermindDL1

Nah I bet that was them, I’m surprised they are not unicode compliant, that sounds like a pending PR if they would take it, though considering its built for ‘elixir identifiers’, maybe not… ^.^

Where Next?

Popular in Announcing Top

Qqwy
Hello everyone, I wrote a small library today called MapDiff. It returns a map listing the (smallest amount of) changes to get from map...
New
Azolo
Hey everyone, I just released WebSockex which is a Elixir WebSocket client. WebSockex strives to work as a OTP special process, be RFC6...
New
michalmuskala
Hello everybody. I have just released Jason - a new JSON library. You might be wondering, why do we need a new library? The primary foc...
New
josevalim
Yes, yet another parser combinator library! Most of the parser combinators in the ecosystem are either compile-time, often using AST tra...
159 19951 141
New
anshuman23
Hello all, I have been working on my proposed project called Tensorflex as part of Google Summer of Code 2018.. Tensorflex can be used f...
New
dominicletz
Hi, I thought I had posted my library before but seems I hadn’t. The project is still in early stages but it’s growing and so I think it...
New
zachdaniel
Ash Framework What is Ash? Ash Framework is a declarative, resource-oriented application development framework for Elixir. A resource can...
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 31586 112
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 49266 226
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
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
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New

We're in Beta

About us Mission Statement