curl

Содержание
Введение
Установка curl
GET
PUT
PUT: передать число
POST
DELETE
Связанные статьи
Тестирование API изображение с сайта www.aredel.com
Фото: freepik.com

Введение

В этой статье вы можете узнать, как выполнить запросы к REST API, с помощью популярной утилиты curl.

Запросы можно делать к моему второму сайту - answerit.ru , который сделан специально для обучения QA-инженеров. Посмотреть документацию к API можно здесь

Задать вопрос в телеграм @aofeedchat

Поддержать проект

Установка curl

Сперва нужно проверить установлен ли curl

curl -V

Command 'curl' not found, but can be installed with:

sudo apt install curl

Если не установлен - нужно выполнить

sudo apt install -y curl

А если у вас CentOS , Rocky , RedHat или другой .rpm то

sudo yum install -y curl

[sudo] password for andrei: Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: curl 0 upgraded, 1 newly installed, 0 to remove and 6 not upgraded. Need to get 161 kB of archives. After this operation, 411 kB of additional disk space will be used. Get:1 http://fi.archive.ubuntu.com/ubuntu focal-updates/main amd64 curl amd64 7.68.0-1ubuntu2.4 [161 kB] Fetched 161 kB in 0s (2,485 kB/s) Selecting previously unselected package curl. (Reading database ... 302218 files and directories currently installed.) Preparing to unpack .../curl_7.68.0-1ubuntu2.4_amd64.deb ... Unpacking curl (7.68.0-1ubuntu2.4) ... Setting up curl (7.68.0-1ubuntu2.4) ... Processing triggers for man-db (2.9.1-1) ...

После установки нужно убедиться в успехе

curl -V

curl 7.68.0 (x86_64-pc-linux-gnu) libcurl/7.68.0 OpenSSL/1.1.1f zlib/1.2.11 brotli/1.0.7 libidn2/2.2.0 libpsl/0.21.0 (+libidn2/2.2.0) libssh/0.9.3/openssl/zlib nghttp2/1.40.0 librtmp/2.3 Release-Date: 2020-01-08 Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp Features: AsynchDNS brotli GSS-API HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM NTLM_WB PSL SPNEGO SSL TLS-SRP UnixSockets

GET

curl -X GET https://www.answerit.ru/flaskapi/api/get

200

С header

curl --request GET \ --url https://example.com/engine/api/v1/wfs \ --header 'Authorization: Bearer a-proper-token-goes-here' \ --header 'accept: application/json'

PUT

curl -X PUT https://www.answerit.ru/flaskapi/api/put

200

PUT с числом

curl -X PUT https://www.answerit.ru/flaskapi/api/order/2020

Order with id 2020 was added to the system. Thank you!

curl --request PUT \ --url https://example.com/engine/api/v1/wfs/wf_id \ --header 'Authorization: Bearer a-proper-token-goes-here' \ --header 'accept: application/json' \ --header 'content-type: application/json' \ --data ' { "status": "WAITING", "approver_can_revoke": true, "target_role_revoked": false, "can_bypass_revoke_wf": false, "name": "name" } '

POST

curl -X POST https://www.answerit.ru/flaskapi/api/post/1961

Post 1961

curl --request POST \ --url https://example.com/engine/api/v1/wfs \ --header 'Authorization: Bearer a-proper-token-goes-here' \ --header 'accept: application/json' \ --header 'content-type: application/json' \ --data ' { "status": "WAITING", "approver_can_revoke": true, "target_role_revoked": false, "can_bypass_revoke_wf": false, "steps": [ { "name": "step", "match": "ANY" } ], "grant_type": "PERMANENT", "name": "name" } '

DELETE

curl --request DELETE \ --url https://example.com/engine/api/v1/wfs/wf_id \ --header 'Authorization: Bearer a-proper-token-goes-here' \ --header 'accept: application/json'

Article author: Andrei Olegovich

Похожие статьи
Linux
Debian
Ubuntu
CentOS
Rocky
Bash
Network Configuration
Files
Examine Free Disk Space
Combine .pdf Files
diff: Compare Files
find: Search for Files
kill: Finish Process
rename
make
signal: System Signals
env: Environmental Variables
localectl: langugae
systemctl: List of Active Services
Firewall
SCP: File Exchange
SSH: Remote Access
cron: Tasks in Timetable
sudo
Monitoring
C
C++
Список открытых API

Search this site

Subscribe to Telegram channel @aofeed to follow new articles and updates to old ones

Go to channel

@aofeed

Ask a question in the Telegram group

@aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: