-
-
Notifications
You must be signed in to change notification settings - Fork 181
CRUD Curl Jets Tutorial
Tung Nguyen edited this page Aug 11, 2018
·
4 revisions
Here's a CRUD demo for Jets with curl. Note, I'm using jq to pretty print the json responses.
$ curl -s http://localhost:8888/posts | jq .
{
"action": "index",
"posts": [
{
"created_at": "2017-11-04T01:46:03Z",
"id": "myid",
"title": "test title",
"updated_at": "2017-11-04T01:46:03Z",
"desc": "test desc"
}
]
}
$ curl -s http://localhost:8888/posts/new | jq .
{
"action": "new"
}
curl -X POST \
http://localhost:8888/posts \
-H 'Content-Type: application/json' \
-d '{
"post": {
"title": "test title"
}
}
'
{
"action": "create",
"post": {
"id": "myid",
"title": "test title",
"desc": "test desc",
"created_at": "2017-11-04T01:46:03Z",
"updated_at": "2017-11-04T01:46:03Z"
}
}
$ curl -s http://localhost:8888/posts/myid | jq .
{
"action": "show",
"post": {
"created_at": "2017-11-04T01:46:03Z",
"id": "myid",
"title": "test title",
"updated_at": "2017-11-04T01:46:03Z",
"desc": "test desc"
}
}
$ curl -s http://localhost:8888/posts/myid/edit | jq .
{
"action": "edit",
"post": {
"created_at": "2017-11-04T01:46:03Z",
"id": "myid",
"title": "test title",
"updated_at": "2017-11-04T01:46:03Z",
"desc": "test desc"
}
}
$ curl -s -X PUT \
http://localhost:8888/posts/myid \
-d '{
"title": "updated test title",
"desc": "updated test desc"
}' | jq .
{
"action": "update",
"post": {
"id": "43fe25329f857dc9917160f2e0aac6cdb932c8b8",
"title": "updated test title",
"desc": "updated test desc",
"created_at": "2017-11-04T01:56:22Z",
"updated_at": "2017-11-04T01:56:22Z"
}
}
$ curl -s -X DELETE http://localhost:8888/posts/myid | jq .
{
"action": "delete"
}