Hi Team,
when I run the below code I get error , please help me to fix as I am testing a new project with Genie.
module App
using Genie
using Genie.Router
using Genie.Renderer
using Genie.Requests
using Genie.Renderer.Json
#using Genie.Requests.Params
include("add.jl")
using Genie.Renderer.Json
route("/add", method = POST) do
data = jsonpayload()
a = parse(Int, data["a"])
b = parse(Int, data["b"])
sum = add(a, b)
return JSON(:result => sum)
end
end
Add function code
function add(a::Int, b::Int)
return a + b
end
when I send a below curl request I get error
curl -X POST 'http://localhost:8000/add/' -H 'Content-Type: application/json' -d '{"a": "10","b": "28"}'
{"error":"500 Internal Error - UndefVarError: `JSON` not defined\nStacktrace:\n [1] (::Main.App.var\"#1#2\")()\n
@ Main.App /home/shiva/gitcode/Maths-project/module/Genie/genie.jl:16\n [2] run_route(r::Genie.Router.Route)\n
@ Genie.Router ~/.julia/packages/Genie/3gPCR/src/Router.jl:535\n [3] route_request(req::HTTP.Messages.Request, res::HTTP.Messages.Response)\n
@ Genie.Router ~/.julia/packages/Genie/3gPCR/src/Router.jl:171\n [4] handle_request(req::HTTP.Messages.Request, res::HTTP.Messages.Response)\n
@ Genie.Server ~/.julia/packages/Genie/3gPCR/src/Server.jl:278\n [5] (::Genie.Server.var\"#29#30\"{HTTP.Messages.Request, HTTP.Messages.Response})()\n
@ Genie.Server /home/shiva/julia/julia-1.10.4/share/julia/stdlib/v1.10/Distributed/src/macros.jl:123\n [6] #invokelatest#2\n
@ ./essentials.jl:892 [inlined]\n [7] invokelatest\n @ ./essentials.jl:889 [inlined]\n [8] #153\n
@ /home/shiva/julia/julia-1.10.4/share/julia/stdlib/v1.10/Distributed/src/remotecal