Use curl to send REST queries

Privalov Vladimir
1 min readSep 5, 2019

--

curl is useful tool to send requests to REST APIs. You can use it to test your API server from terminal.

Basic usage:

curl -v -X<type> -H <headers> -F <param1> -F <param2> <api_url>

In headers we can set Authorization token or Content-Type of request.

Let’s try GET query — e.g. get all categories of items

curl -v -XGET -H 'Authorization: Token __API_TOKEN__' <some_api_server>/category/

Some more complicated case. Let’s send POST query with some array data

curl -v -XPOST -H 'Authorization: Token __API_TOKEN__' -H Content-Type:application/json --data '{"detection_label": "__LABEL_ID__", "image": "__IMAGE_ID__", "data": [xmin, ymin, xmax, ymax] }' <some_api_server>/detection

He we wrap array in JSON record.

Let’s try authenticated request with user credentials

curl -v -u "<login>:<password>" http://127.0.0.1:5000/login

That’s it. Enjoy Linux and good luck.

--

--

No responses yet