curl
Summary #
cURL, which stands for client URL, is a command line tool that developers use to transfer data to and from a server. At the most fundamental, cURL lets you talk to a server by specifying the location (in the form of a URL) and the data you want to send.
Can be considered as non-interactive web browser of terminal/shell.
curl CS #
Authorization with headers #
sending headers and authorizations to get response -H -> –header
curl https://testlogin.kfupm.edu.sa/oauth2/userinfo \
-H "Accept: application/json" \
-H "Authorization: Bearer 616af0af-db00-355f-bd77-8be597aec24c"
Sending data #
-d -> –data
curl -d "param1=value1¶m2=value2" \
-H "Content-Type: application/x-www-form-urlencoded" \
-X POST http://localhost:3000/data
# or as dictionary
curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST http://localhost:3000/data
# or as file
curl -d "@data.txt" -X POST http://localhost:3000/data
Sending form with file #
-F -> –form
curl -X 'POST' \
'localhost:8000/api/' \
-F "image=@path/to/image" \ # file
-F "task=product_crop" \ # data
-F "image_name=some-name" # data
Tadafuq API #
Auth #
Register #
curl -X 'POST' \
'http://localhost:3001/api/v1/auth/register' \
-H 'accept: */*' \
-H 'Content-Type: application/json' \
-d '{
"channelName": "test channel-1",
"email": "test1@test.com",
"password": "p@ssw0rd"
}'
login #
User
curl -X 'POST' \ 'http://localhost:3001/api/v1/auth/login' \ -H 'accept: */*' \ -H 'Content-Type: application/json' \ -d '{ "email": "test1@example.com", "password": "TTVjhd9yjREXdOVcbe4b" }'
Admin
curl -X 'POST' \ 'http://localhost:3001/api/v1/auth/login' \ -H 'accept: */*' \ -H 'Content-Type: application/json' \ -d '{ "email": "admin@example.com", "password": "znhWSmsFzYOjI5gybz7u" }'
Authme #
curl 'http://localhost:3001/api/v1/auth/me' \
-H 'accept: */*' \
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYyMjBhN2FiYzljZDM4N2FmYzhkZTE5ZSIsImlhdCI6MTY0OTkyNTUzMiwiZXhwIjoxNjUyNTE3NTMyfQ.lpCHBjv1CjynqlRLRWwwPJmaJhIi2NhWIsIWuy5POYk' \
-d ''
Update Details #
[ ] not working
curl -X 'PUT' 'http://localhost:3001/api/v1/auth/updatedetails' \
-H 'accept: */*' \
-H 'Content-Type: application/json' \
-H 'Authorization: JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYyMjBhN2FiYzljZDM4N2FmYzhkZTE5ZSIsImlhdCI6MTY0OTkyNTUzMiwiZXhwIjoxNjUyNTE3NTMyfQ.lpCHBjv1CjynqlRLRWwwPJmaJhIi2NhWIsIWuy5POYk' \
-d '{
"channelName": "test channel-2",
"email": "test2@test.com"
}'
Avatar #
[ ] not working
curl -X 'PUT' \
'http://localhost:3001/api/v1/auth/avatar' \
-H 'accept: */*' \
-H "Authorization: JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYyNTdkY2MwMjA3Y2I2NDhmNWIwNGZlZiIsImlhdCI6MTY0OTkyNTMxMiwiZXhwIjoxNjUyNTE3MzEyfQ.RDterh1aT9-LFgd7I8mayiUpQbVEuGwmSkTEsGLoSec"
users #
Get users #
curl -X 'GET' 'http://localhost:3001/api/v1/users/' \
-H 'accept: */*' \
-H 'Authorization: JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYyNTdkY2MwMjA3Y2I2NDhmNWIwNGZlZiIsImlhdCI6MTY0OTkyNTMxMiwiZXhwIjoxNjUyNTE3MzEyfQ.RDterh1aT9-LFgd7I8mayiUpQbVEuGwmSkTEsGLoSec'