awendland / bedsheets

Turn Google Sheets into a quick & dirty RESTful DB
MIT License
4 stars 0 forks source link

Gracefully handle POSTs with a single object not in an array #3

Open awendland opened 4 years ago

awendland commented 4 years ago

The POST endpoint expects objects to be in an array, however, users may submit a single object that isn't nested in an array. The endpoint should check for this an wrap it in an array if necessary.

For example this should work instead of returning an error:

body={"type":"article","uri":"https:\/\/stackoverflow.com\/questions\/5725430\/http-test-server-accepting-get-post-requests"}
-->
response={"statusCode":400,"payload":{"message":"The request body must be in the form [{\"header1\": \"value1\", \"header2\": \"value2\"}, ...]"}}
awendland commented 4 years ago

Also support clients that can't send top level arrays, e.g. allow {"data": [...]}