Http://json2elm.com. auto generating json "codecs" (decoders and encoders)
has existed for more than a year already.

On Friday, March 17, 2017, Kasey Speakman <[email protected]> wrote:

> Another update. I figured out how to get the encoders and decoders out of
> the ports using a native module. So I no longer have to actually send
> things across ports (still have to declare them). I can also now use Elm's
> Http module.
>
> Here's a gist of what it takes:
>
> https://gist.github.com/kspeakman/3f9521b0921b352c7d656261ec0a8fa6
>
> On Saturday, February 18, 2017 at 2:22:32 AM UTC-6, Kasey Speakman wrote:
>>
>> An update. I'm using the ports approach to deal with JSON (and also
>> sending the HTTP request). For several months, I've had a small but
>> critical app in production using that. Another project in development is
>> too. In the process, I have run across two additional caveats with this
>> approach.
>>
>>    1. *Ports don't convert undefined properties to Maybe.Nothing.* It's
>>    an open issue from Jan 2016.
>>    <https://github.com/elm-lang/core/issues/476>
>>    For a Maybe property, the JSON must have the property present and set
>>    to null. Otherwise error. This is particularly annoying when you store the
>>    data as JSON and pass it back to the client as-is. To work around this
>>    issue, I either have to waste space storing nulls in the database or waste
>>    (CPU/response) time server-side to inject nulls in the response.
>>
>>    2. *Cmd.map can't be used with this method.*
>>    Using Http module, you can use Cmd.map to take some data from the
>>    request and give it to the response Msg. Using ports, you can't do that.
>>    I've noticed this when the data is easy to provide for a request, but 
>> after
>>    the response comes back it is less convenient to dig out of the model 
>> (e.g.
>>    behind a case statement).
>>
>> Neither of these are blockers for me, just nuisance issues. It still
>> beats maintaining codecs.
>>
>> I've seen rumblings about tools for code-gen'ing JSON codecs for us (maybe
>> elm-format? <https://github.com/avh4/elm-format/issues/194> There also
>> exists elm-swagger, but I don't use swagger.). I dunno though. Where
>> possible, I tend to avoid code-gen because it's for handling a really
>> tedious problem. And if the code-gen fails, then I have to handle a really
>> tedious problem. (XSD/WSDL flashbacks.)
>>
>> All it would really take for a profound QoL improvement are a couple of
>> "special" functions on Http that handle data exactly like ports do now...
>> just saying.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Elm Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected]
> <javascript:_e(%7B%7D,'cvml','elm-discuss%[email protected]');>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to