Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json Payload #57

Open
devnacho opened this issue Jan 19, 2019 · 2 comments
Open

Json Payload #57

devnacho opened this issue Jan 19, 2019 · 2 comments

Comments

@devnacho
Copy link

devnacho commented Jan 19, 2019

Hi @wookay,

I've updated to 0.4.1 but when receiving a JSON payload, it seems like the payload is not being parsed correctly. I followed this example https://github.com/wookay/Bukdu.jl/blob/master/examples/rest/ex2.jl

The JSON payload is something like this:

{
   "simulation":{
      "id":5927,
       "withdrawal_strategy_frequency": 1
   }
}

and it is being parsed to this type

Assoc(Pair{String,Any}["simulation"=>(id = 5927, withdrawal_strategy_frequency = 1))]

Instead of something like:

(simulation = (id = 5927, withdrawal_strategy_frequency = 1)))

Is there any reason why it might happen this?

@wookay
Copy link
Owner

wookay commented Jan 20, 2019

because the conn.params is a type of Assoc
sometimes it's useful with undefined names like

@info :payload (c.params.message, c.params.x, c.params.y)

if you want to decode the request body directly, try this way

using JSON2

function create(c::RESTController)
json = JSON2.read(IOBuffer(c.conn.request.body))
@info :json json
end

@wookay
Copy link
Owner

wookay commented Jan 23, 2019

in Bukdu v0.4.2, you could plug(Plug.Parsers, :json => Plug.ContentParsers.JSONDecoder, parsers=[:json])
see https://github.com/wookay/Bukdu.jl/blob/v0.4.2/examples/rest/ex3.jl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants