Run curl request uppon a node.js server

nodejs

#1

Hi all,

I’d like to run curl requests on my node.js server to test my API but it looks like it doesn’t work. Maybe this is normal…
Request launched :

curl -H "Accept: application/json" -H "Content-type: application/json; charset=UTF-8" -X POST -d @./order/addOrder.json https://[workspace]-[username]-1.c9users.io:8080/api/order/addOrder

My server is of course running on port 8080.

ps: It works well on a local environnement or when the application is deployed on an hosted server.

Thanks :slight_smile:


#2

If it’s just for testing, change your URL so that it uses HTTP and localhost:

curl -H "Accept: application/json" \
-H "Content-type: application/json; charset=UTF-8" \
-X POST -d @./order/addOrder.json \
http://locahost:8080/api/order/addOrder

I’m assuming that your running curl in the same system as your server.


#3

Is your application preview set to “public”? You can do that via the share button in the top right. If not you won’t be able to curl as you need to authenticate to access it.


#4

@timjrobinson & @arielortiz Thanks for your quick your answers.
Actually setting the application preview to “public” did the trick.

Example command:
curl -H "Accept: application/json" -H "Content-type: application/json; charset=UTF-8" -X POST -d @./order/addOrder.json http://[workspace]-[username]-1.c9users.io:8080/api/order/addOrder
(Using http, not https)