luna icon indicating copy to clipboard operation
luna copied to clipboard

Accept JSON POST data

Open DEGoodmanWilson opened this issue 6 years ago • 2 comments

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.

DEGoodmanWilson avatar Oct 05 '18 14:10 DEGoodmanWilson

For application/json, what should the validations look like?

rjalfa avatar Oct 06 '18 03:10 rjalfa

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.

DEGoodmanWilson avatar Oct 07 '18 13:10 DEGoodmanWilson