How to make APIFunction
get its parameters from the body?
By default it uses the request URI, which is first insecure, and second, won't allow me to pass e.g. images to the function.
Ultimately the body can be extracted by using HTTPRequestData
HTTPRequestData[]
will return an Association
containing properties and values. Usually you can specify the specific property you want, like "Body"
(I seem to remember some issues getting "MultipartElements"
at some point in time).
obj = CloudDeploy[APIFunction[{}, HTTPRequestData["Body"] &]]
URLExecute[obj, {},
"Body" -> "\"test body\"",
"Headers" -> {"content-type" -> "text/plain" (*or whatever is appropriate*)},
Method -> "POST"]
"test body"
If your API is actually attached to a form, and your header when making the request is something like:
Content-Type: multipart/form-data
you can use the following
CloudDeploy[APIFunction[{"i"-> "Image"}, #i &,"PNG"]]
This will echo back the image "i" (as labeled in your form). I put "PNG" for display purposes, you should change it to fit your needs.
Missing["NotAvailable"]
.
$\endgroup$
APIFunction[{}, HTTPRequestData["Body"] &]
acceptable? $\endgroup$