Skip to content

Instantly share code, notes, and snippets.

@kienbt01359
Last active July 20, 2018 20:29
Show Gist options
  • Save kienbt01359/6946609 to your computer and use it in GitHub Desktop.
Save kienbt01359/6946609 to your computer and use it in GitHub Desktop.

#Some curl sample commands in sample application ##Gett a cookie.

$ curl http://localhost:3000/users/new --cookie-jar "cookie.txt"

after this command, you will see a authenticity_token, please remember it.

##Sign Up

$ curl http://localhost:3000/users --request POST --data "authenticity_token=NCRWZ8JuQs6AFsQg9tw0TP26LyPAnG/ashI0iyMCF8w=" --cookie "cookie.txt" –data “user[name]=kien” --data "user[email]=btkfpt@gmail.com" --data "user[password]=foobar" --data "user[password_confirmation]=foobar"

##Sign_in

$ curl http://localhost:3000/sessions --request POST --data "authenticity_token=NCRWZ8JuQs6AFsQg9tw0TP26LyPAnG/ashI0iyMCF8w=" --cookie-jar “cookie.txt” --cookie "cookie.txt" --data "session[email]=btkfpt@gmail.com" --data "session[password]=foobar"

##Update User

$ curl http://localhost:3000/users/2 --request PUT --data "authenticity_token=NCRWZ8JuQs6AFsQg9tw0TP26LyPAnG/ashI0iyMCF8w=" --cookie "cookie.txt" --data "user[email]=kienbt01359@fpt.edu.vn" --data "user[name]=Kien Bui"

##Sign Out

curl http://localhost:3000/signout --request DELETE --data-urlencode "authenticity_token=nGFGBMJfg3xN7dR/zDDsTuHtP7e8szod57BFvB7D+5I=" --cookie-jar "cookie.txt" --cookie "cookie.txt"

##Create new post

$ curl http://localhost:3000/microposts --request POST --cookie-jar "cookie.txt" --cookie "cookie.txt" --data-urlencode "authenticity_token=nGFGBMJfg3xN7dR/zDDsTuHtP7e8szod57BFvB7D+5I=" --data "micropost[content]=cURL Test" --data "micropost[user_id]=2"

##Delete a post

 $ curl http://localhost:3000/microposts/2 --request DELETE --data-urlencode "authenticity_token=nGFGBMJfg3xN7dR/zDDsTuHtP7e8szod57BFvB7D+5I=" --cookie-jar "cookie.txt" --cookie "cookie.txt"

##Follow user

$ curl http://localhost:3000/relationships --request POST --data-urlencode "authenticity_token=nGFGBMJfg3xN7dR/zDDsTuHtP7e8szod57BFvB7D+5I=" --cookie-jar "cookie.txt" --cookie "cookie.txt" --data "relationship[followed_id]=1"

##Unfollow user

$ curl http://localhost:3000/relationships/1 --request DELETE --data-urlencode "authenticity_token=nGFGBMJfg3xN7dR/zDDsTuHtP7e8szod57BFvB7D+5I=" --cookie-jar "cookie.txt" --cookie "cookie.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment