Closed glennlawyer closed 6 years ago
i might be wrong but i think you need the -F
parameter for posting the json file
curl -X POST -F @moods.json http://159.XXX.XXX.XXX/moodgraph/ --header "Content-Type:application/json"
Solved it!!!
The problem was a path error. My plumber file defines the endpoint as
#* @post /moodgraph
function(moods)
My deploy file sets the endpoint as
do_deploy_api(drop, "moodgraph", "./digiocean", 8000)
Thus the proper cURL path is
http://159.XXX.XXX.XXX/moodgraph/moodgraph
where (I believe) the first "moodgraph" is the name set by do_deploy_api
and the second "moodgraph" in the path is set by my plumber.R
file
and
curl -X POST -d @moods.json http://159.XXX.XXX.XXX/moodgraph/moodgraph --header "Content-Type:application/json"
produces the expected result.
@david-jankoski Thanks for the tip.
Love the plumber package so far. Everything works on my local machine (running from R, running from a docker container), but when deploying to DigitalOcean, I cannot access the API using cURL. It is likely to be an IAK (idiot at keyboard) error, but the docs are a bit sparse and I don't see where I've gone wrong.
My question: What is the proper way to call the API using cURL?
I'm following this tutorial:
http://www.exegetic.biz/blog/2017/06/deploying-minimal-plumber-api-digitalocean/
, and deploying their toy API as follows:where the file "api/plumber.R" is
The instance builds and provisions on DigitalOcean as it should. Opening the URL
http://159.XXX.XXX.XXX/date
in my browser shows the date. That's where the tutorial ends, no cURL example.But the following:
returns
Also tested it with my real api, which expects a post request. Again, the api works fine running locally on my machine or in a docker container. I try deploying to DigitalOcean via
which (according to the R console) deploys properly.
But the curl commands
or
returns the same 301.
What is the proper way to call the API using cURL?