-
-
Notifications
You must be signed in to change notification settings - Fork 183
CRUD Curl Jets Tutorial ActiveRecord
Tung Nguyen edited this page Dec 24, 2017
·
3 revisions
Here's a CRUD demo for Jets with curl. Note, I'm using jq to pretty print the json responses.
jets new store
cd store
jets server # do this in another terminal
open http://localhost:8888 # should see Jets welcome page
jets generate scaffold Toy name --api
jets db:create db:migrate
$ curl -s http://localhost:8888/toys | jq .
[]
$ curl -s -X POST http://localhost:8888/toys -d '{
"toy": {
"name": "train"
}
}' | jq '.'
{
"id": 1,
"name": "train",
"created_at": "2017-12-24T02:47:20.164Z",
"updated_at": "2017-12-24T02:47:20.164Z"
}
$ curl -s http://localhost:8888/toys/1 | jq '.'
{
"id": 1,
"name": "train",
"created_at": "2017-12-24T02:47:20.164Z",
"updated_at": "2017-12-24T02:47:20.164Z"
}
$ curl -s -X PUT
http://localhost:8888/toys/1
-d '{
"toy": {
"name": "train set"
}
}' | jq .
{
"id": 1,
"name": "train set",
"created_at": "2017-12-24T02:47:20.164Z",
"updated_at": "2017-12-24T02:49:00.860Z"
}
$ curl -s -X DELETE http://localhost:8888/toys/1 | jq .
{
"deleted": true
}