Elixir and parameter validation on APIs
- Dominant language
- JavaScript
- Stars
- 291
- Forks
- 25
- PR merge metrics
- No merged PRs in 30d
Description
`JSON` schema validation is usually a must when implementing an API.
When the API is simple, you can probably get away with simple validations but when you have multiple possible query or URI parameters, keeping its validation clean and concise helps with readability.
There is some discussion on how to do this with Elixir/Phoenix:
- https://www.reddit.com/r/elixir/comments/m63p21/some_thoughts_around_elixir_json_schema_validator/
- https://elixirforum.com/t/whats-the-standard-for-validating-json-bodies-for-an-api/14837
Using `Ecto.Changesets` is usually the standard. Although I personally use `Changesets` for validation on a **database level**, it might be not the same situation for validation on an **API-level**, where we might want another set of constraints to be met.
[Schemaless changesets](https://elixirfocus.com/posts/ecto-schemaless-changesets/) can (and should!) be actually used for this. But I feel like this produces a considerable amount of boilerplate code.
With this in mind, I've taken a gander and found [`goal`](https://github.com/martinthenth/goal), which seems to make this process painless and make code much more comprehensible, as errors are returned on an atom-basis.
Just food for thought 🧠
Contributor guide
Assessment
This issue has not been assessed yet.