mamantoha / crest

HTTP and REST client for Crystal
https://mamantoha.github.io/crest/
MIT License
235 stars 14 forks source link

JSON params not accepting Int64 values #163

Closed kates closed 2 years ago

kates commented 2 years ago
  response = Crest.post(url, {
    "name" => "hello",
    "time" => Time.utc.to_unix
  }, json: true)

The code above will not compile with the following message

Showing last frame. Use --error-trace for full trace.

In lib/crest/src/crest/params_encoder.cr:105:16

 105 | memo << {processed_key, v}
            ^-
Error: no overload matches 'Array(Tuple(String, Bool | File | Int32 | String | Symbol | Nil))#<<' with type Tuple(String, Int32 | Int64 | String)

Overloads are:
 - Array(T)#<<(value : T)

Integer values in Crystal JSON are Int64. Currently, I worked around this issue by editing Crest's source to include Int64 in the ParamsValue type.

alias ParamsValue = Bool | Int32 | String | Symbol | Nil | File? | Int64 <--- this one
mamantoha commented 2 years ago

Hi @kates . Thanks for your contribution. Fixed in v1.0.1.