-
Notifications
You must be signed in to change notification settings - Fork 28
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 requests support #73
Comments
The primary purpose of this package is to enable exposing Julia functions as web APIs. Right now, the path elements are mapped to function parameters and query/form name-value pairs are mapped on to keyword args. I unsure how requests with JSON body should fit to this paradigm. |
Actually Web APIs primary means usage of some exchange format like JSON or XML. Just as example - https://market.mashape.com/ or open API initiative https://www.openapis.org/ But in both cases it requires usage of POST request with some HTTP body content. In general it is not so big issue to add support of multipart HTTP content at least for JSON. But primary it is depends on how are you positioning the library. |
|
Implementation of JSON request processing with Mux: using Mux
using JSON
@app test = (
Mux.defaults,
page(respond("<h1>Hello World!</h1>")),
page("/user/:user", req -> "<h1>Hello, $(req[:params][:user])!</h1>"),
route("/resource/process", req -> begin
obj = JSON.parse(String(req[:data]))
@show obj
Dict(:body => String(JSON.json(obj)),
:headers => Dict("Content-Type" => "application/json")
)
end),
Mux.notfound())
serve(test, 8080)
Base.JLOptions().isinteractive == 0 && wait() Implementation of JSON request processing with Bukdu: using Bukdu
using JSON
struct WelcomeController <: ApplicationController
conn::Conn
end
function index(c::WelcomeController)
render(JSON, "Hello World")
end
function process_resource(c::WelcomeController)
json = JSON.parse(String(c.conn.request.body))
@show json
render(JSON, json)
end
routes() do
get("/", WelcomeController, index)
post("/resource/process", WelcomeController, process_resource)
end
Bukdu.start(8080)
Base.JLOptions().isinteractive == 0 && wait() |
I'm trying to process POST requests with JSON body. For now I don't see a way how to do it.
parsepostdata
doesn't recognize the headerContent-Type: application/json
and interprets the data as parameters of a query only.Any suggestions why it is not implemented? Should I use other libraries for JSON processing like Mux.jl or is it just non implemented feature?
The text was updated successfully, but these errors were encountered: