You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. How about you cast incoming data keys into atoms, if the user supplies some argument, like keys_to_atoms: true
The reason for this is that in the function (e.g. in some "service" layer in your code) you don't want to check all the time if the string or atom key exists, you just want to work with one of them. Jason and Poison have options for this, for example.
2. Casting to primitive types would be great. That would be something similar to what Ecto Changeset is doing. Because you already have the spec with the type specified there, basically only the implementation is missing, spec is fine. This can be a separate function of course so you don't break old versions.
The reason for this is that you typically want to have a separate controller/frontend layer which deals with HTTP etc. - and over there the params received will have string keys and string types (especially if sent as form encoded and not as JSON). You want the layer like skooma to normalize params so that you can handle only one case in your service layer.
For example age: :integer should turn up as params.age (integer type) and you can then easily do your business logic because:
No messing around guessing key type (string or atom)
You know that the data "structure" is valid
You have the correct types so you can immediately work on them without transformations and checks, and catching errors for all that.
The text was updated successfully, but these errors were encountered:
Hi,
more ideas:
1. How about you cast incoming data keys into atoms, if the user supplies some argument, like keys_to_atoms: true
The reason for this is that in the function (e.g. in some "service" layer in your code) you don't want to check all the time if the string or atom key exists, you just want to work with one of them. Jason and Poison have options for this, for example.
2. Casting to primitive types would be great. That would be something similar to what Ecto Changeset is doing. Because you already have the
spec
with the type specified there, basically only the implementation is missing,spec
is fine. This can be a separate function of course so you don't break old versions.The reason for this is that you typically want to have a separate controller/frontend layer which deals with HTTP etc. - and over there the params received will have string keys and string types (especially if sent as form encoded and not as JSON). You want the layer like
skooma
to normalize params so that you can handle only one case in your service layer.For example age: :integer should turn up as params.age (integer type) and you can then easily do your business logic because:
The text was updated successfully, but these errors were encountered: