Created
December 22, 2023 08:55
-
-
Save rithik-sandron/d4dc5998a668539793d889175910d412 to your computer and use it in GitHub Desktop.
Basic crud requests using curl. Test your APIs though shell script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/zsh | |
# routes => /p POST | /:slug => GET DELETE PUT | |
uri=localhost:3000 | |
post_url=p | |
DATA='{ | |
"title": "Markdown is good", | |
"content": "No bytes, no problem. Just insert a document, in MongoDB" | |
}' | |
# POST | |
echo "POST" | |
post_res=$(curl -X POST -H "Content-Type: application/json" $uri/$post_url -d $DATA) | |
echo $post_res | |
echo "\n" | |
#GET | |
echo "GET" | |
curl -X GET $uri/$slug | |
echo "\n" | |
UPDATED_DATA='{ | |
"title": "Markdown is good", | |
"content": "No bytes, no problem. Just insert a document, in MongoDB updated" | |
}' | |
#PUT | |
put_res=$(curl -X PUT -H "Content-Type: application/json" $uri/$slug -d $UPDATED_DATA) | |
echo $put_res | |
echo "\n" | |
#GET | |
echo "GET" | |
curl -X GET $uri/$slug | |
echo "\n" | |
#DELETE | |
echo "DELETE" | |
del_res=$(curl -X DELETE $uri/$slug) | |
echo $del_res | |
echo "\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment