https://github.com/operable/conduit
JSON encoder/decoder with strong typing and validation
https://github.com/operable/conduit
Last synced: 8 months ago
JSON representation
JSON encoder/decoder with strong typing and validation
- Host: GitHub
- URL: https://github.com/operable/conduit
- Owner: operable
- License: other
- Created: 2016-07-25T13:06:10.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-25T13:44:07.000Z (over 8 years ago)
- Last Synced: 2025-02-24T10:36:38.401Z (about 1 year ago)
- Language: Elixir
- Size: 34.2 KB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Conduit
[](https://travis-ci.org/operable/conduit)
[](https://coveralls.io/github/operable/conduit?branch=master)
[](https://ebertapp.io/github/operable/conduit)
Typed and validated JSON encoder and decoder
## Installation
```elixir
def deps do
[{:conduit, github: "operable/conduit", branch: "master"}]
end
```
## Usage
### Defining Conduit structs
```elixir
defmodule MyApp.User do
use Conduit
field :first_name, :string, required: true
field :last_name, :string, required: true
field :userid, :string, required: true
end
defmodule MyApp.Request do
use Conduit
field :command, :string, required: true
field :args, array: :string
field :requestor, object: MyApp.User
end
```
### Marshaling and unmarshaling
```elixir
try do
request = MyApp.Request.decode!(json)
rescue
e in Conduit.ValidationError ->
log_bad_data(e, json)
end
```
### Validation
```elixir
request = MyApp.Request.decode!(json) |> evaluate_args
try do
request.validate!
rescue
e in Conduit.ValidatinError ->
log_bad_args(e, json)
end
```