luna
luna copied to clipboard
Accept JSON POST data
At the moment, on POST endpoints, we only accept application/x-www-form-urlencoded
parameters for validation in router::handle_request
. We don't even check the Content-Type
header. Add support for application/json
-encoded data as well.
For application/json
, what should the validations look like?
A really excellent question, because of course JSON data could be totally free-form, and not at all a set of key-value pairs.
This is also a bit bigger than validation. There is a unordered_map
of query parameters that gets passed in as well, and that maybe should be populated.
Perhaps what we could do is see if the JSON is an object, and then validate the object members as though they were a listing of key-value pairs. Then also populate the query parameter map.
I'm not 💯 on board with this idea, though. Maybe there are better ideas.