Save curl output

save curl output response to a file

$ curl -o jsonplaceholder.html https://jsonplaceholder.typicode.com/

In [1]:
!curl -o todos-1.json https://jsonplaceholder.typicode.com/todos/1


  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100    83  100    83    0     0    313      0 --:--:-- --:--:-- --:--:--   313

In [2]:
!cat todos-1.json


{
  "userId": 1,
  "id": 1,
  "title": "delectus aut autem",
  "completed": false
}

HTTP Methods with curl

GET


In [4]:
! curl  https://jsonplaceholder.typicode.com/photos/1


{
  "albumId": 1,
  "id": 1,
  "title": "accusamus beatae ad facilis cum similique qui sunt",
  "url": "https://via.placeholder.com/600/92c952",
  "thumbnailUrl": "https://via.placeholder.com/150/92c952"
}
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   205  100   205    0     0   1191      0 --:--:-- --:--:-- --:--:--  1191

POST


In [5]:
! curl  "https://jsonplaceholder.typicode.com/users/10"


{
  "id": 10,
  "name": "Clementina DuBuque",
  "username": "Moriah.Stanton",
  "email": "Rey.Padberg@karina.biz",
  "address": {
    "street": "Kattie Turnpike",
    "suite": "Suite 198",
    "city": "Lebsackbury",
    "zipcode": "31428-2261",
    "geo": {
      "lat": "-38.2386",
      "lng": "57.2232"
    }
  },
  "phone": "024-648-3804",
  "website": "ambrose.net",
  "company": {
    "name": "Hoeger LLC",
    "catchPhrase": "Centralized empowering task-force",
    "bs": "target end-to-end models"
  }
}
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   511  100   511    0     0   1921      0 --:--:-- --:--:-- --:--:--  1921

In [7]:
! curl "https://jsonplaceholder.typicode.com/users/id=10&username=Moria.Stanley"


{}
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100     2  100     2    0     0      7      0 --:--:-- --:--:-- --:--:--     7

In [8]:
! curl  "https://jsonplaceholder.typicode.com/users/10"


{
  "id": 10,
  "name": "Clementina DuBuque",
  "username": "Moriah.Stanton",
  "email": "Rey.Padberg@karina.biz",
  "address": {
    "street": "Kattie Turnpike",
    "suite": "Suite 198",
    "city": "Lebsackbury",
    "zipcode": "31428-2261",
    "geo": {
      "lat": "-38.2386",
      "lng": "57.2232"
    }
  },
  "phone": "024-648-3804",
  "website": "ambrose.net",
  "company": {
    "name": "Hoeger LLC",
    "catchPhrase": "Centralized empowering task-force",
    "bs": "target end-to-end models"
  }
}
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   511  100   511    0     0   2333      0 --:--:-- --:--:-- --:--:--  2333

Delete


In [9]:
! curl -X DELETE https://jsonplaceholder.typicode.com/users/10


{}
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100     2  100     2    0     0      4      0 --:--:-- --:--:-- --:--:--     4

In [10]:
!curl https://jsonplaceholder.typicode.com/users/10


{
  "id": 10,
  "name": "Clementina DuBuque",
  "username": "Moriah.Stanton",
  "email": "Rey.Padberg@karina.biz",
  "address": {
    "street": "Kattie Turnpike",
    "suite": "Suite 198",
    "city": "Lebsackbury",
    "zipcode": "31428-2261",
    "geo": {
      "lat": "-38.2386",
      "lng": "57.2232"
    }
  },
  "phone": "024-648-3804",
  "website": "ambrose.net",
  "company": {
    "name": "Hoeger LLC",
    "catchPhrase": "Centralized empowering task-force",
    "bs": "target end-to-end models"
  }
}
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   511  100   511    0     0    990      0 --:--:-- --:--:-- --:--:--   990

Install JSON-server

http://nmotw.in/json-server/

https://github.com/typicode/json-server

$ npm install -g json-server

$ json-server --watch db.json

get the entire db


In [20]:
!curl  http://localhost:3000/db


{
  "posts": [
    {
      "id": 1,
      "title": "json-server",
      "author": "typicode"
    },
    {
      "id": 3,
      "title": "Docker",
      "author": "shipper"
    },
    {
      "title": "learn Ansible",
      "author": "annabella",
      "id": "21"
    },
    {
      "id": 4,
      "title": "apache-server",
      "author": "apache"
    },
    {
      "id": "5",
      "title": "learn Docker Compose",
      "author": "Mei"
    },
    {
      "id": "2",
      "title": "Play with Jenkins",
      "author": "oracle"
    }
  ],
  "comments": [
    {
      "id": 1,
      "body": "json-server",
      "postId": 1
    },
    {
      "id": 2,
      "body": "easy to use",
      "postId": 1
    },
    {
      "id": 4,
      "body": "Docker is fun",
      "postId": 3
    },
    {
      "id": 5,
      "body": "Docker great future",
      "postId": 3
    },
    {
      "id": "6",
      "postId": "4",
      "body": "Apache is powerful"
    }
  ],
  "profile": {
    "name": "typicode"
  }
}
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  1000  100  1000    0     0   4000      0 --:--:-- --:--:-- --:--:--  4255

HTTP Methods

GET - query


In [55]:
!curl  http://localhost:3000/posts


[
  {
    "id": 1,
    "title": "json-server",
    "author": "typicode"
  },
  {
    "id": 2,
    "title": "Selenium",
    "author": "webman"
  },
  {
    "id": 3,
    "title": "Docker",
    "author": "shipper"
  },
  {
    "id": "21",
    "title": "learn REST",
    "author": "wen"
  }
]
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   288  100   288    0     0   1225      0 --:--:-- --:--:-- --:--:--  1225

POST - add new


In [49]:
! curl -X POST -d "id=21&title=learn JSON&author=gong"  http://localhost:3000/posts/


{
  "id": "21",
  "title": "learn JSON",
  "author": "gong"
}
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100    95  100    61  100    34    244    136 --:--:-- --:--:-- --:--:--   380

In [10]:
! curl -X POST -d "id=5&title=learn Docker Compose&author=Mei"  http://localhost:3000/posts/


{
  "id": "5",
  "title": "learn Docker Compose",
  "author": "Mei"
}
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   111  100    69  100    42    294    179 --:--:-- --:--:-- --:--:--   474

In [14]:
! curl -X POST -d "id=2&title=Play with Jenkins&author=oracle"  http://localhost:3000/posts/


{
  "id": "2",
  "title": "Play with Jenkins",
  "author": "oracle"
}
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   111  100    69  100    42    315    191 --:--:-- --:--:-- --:--:--   506

NOTE: JSON-server does not know how to parse JSON string


In [68]:
! curl -i -X POST  http://localhost:3000/posts/ -d '{"id": 6, "title": "learn Jenkins", "author": "gong"}'  --header "Content-Type: application/json"


HTTP/1.1 400 Bad Request
X-Powered-By: Express
Vary: Origin, Accept-Encoding
Access-Control-Allow-Credentials: true
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
Content-Security-Policy: default-src 'self'
X-Content-Type-Options: nosniff
Content-Type: text/html; charset=utf-8
Content-Length: 1256
Date: Sun, 18 Nov 2018 15:19:25 GMT
Connection: keep-alive

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>SyntaxError: Unexpected token &#39; in JSON at position 0<br> &nbsp; &nbsp;at JSON.parse (&lt;anonymous&gt;)<br> &nbsp; &nbsp;at createStrictSyntaxError (C:\Users\WGONG\AppData\Roaming\npm\node_modules\json-server\node_modules\body-parser\lib\types\json.js:158:10)<br> &nbsp; &nbsp;at parse (C:\Users\WGONG\AppData\Roaming\npm\node_modules\json-server\node_modules\body-parser\lib\types\json.js:83:15)<br> &nbsp; &nbsp;at C:\Users\WGONG\AppData\Roaming\npm\node_modules\json-server\node_modules\body-parser\lib\read.js:121:18<br> &nbsp; &nbsp;at invokeCallback (C:\Users\WGONG\AppData\Roaming\npm\node_modules\json-server\node_modules\raw-body\index.js:224:16)<br> &nbsp; &nbsp;at done (C:\Users\WGONG\AppData\Roaming\npm\node_modules\json-server\node_modules\raw-body\index.js:213:7)<br> &nbsp; &nbsp;at IncomingMessage.onEnd (C:\Users\WGONG\AppData\Roaming\npm\node_modules\json-server\node_modules\raw-body\index.js:273:7)<br> &nbsp; &nbsp;at IncomingMessage.emit (events.js:182:13)<br> &nbsp; &nbsp;at endReadableNT (_stream_readable.js:1094:12)<br> &nbsp; &nbsp;at process._tickCallback (internal/process/next_tick.js:63:19)</pre>
</body>
</html>
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  1261  100  1256  100     5   5735     22 --:--:-- --:--:-- --:--:--  5757
curl: (6) Could not resolve host: 6,

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0curl: (6) Could not resolve host: title
curl: (3) Host name 'learn Jenkins,' contains bad letter

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0curl: (6) Could not resolve host: author
curl: (3) [globbing] unmatched close brace/bracket in column 5

PUT - update (whole node)


In [53]:
!curl -X PUT -d "id=21&title=learn REST&author=wen" http://localhost:3000/posts/21


{
  "id": "21",
  "title": "learn REST",
  "author": "wen"
}
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100    93  100    60  100    33    273    150 --:--:-- --:--:-- --:--:--   424

In [57]:
!curl -i -X PUT -d "title=learn Ansible&author=albert" http://localhost:3000/posts/21


HTTP/1.1 200 OK
X-Powered-By: Express
Vary: Origin, Accept-Encoding
Access-Control-Allow-Credentials: true
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
X-Content-Type-Options: nosniff
Content-Type: application/json; charset=utf-8
Content-Length: 66
ETag: W/"42-DXEmJECca3s8x/ZMhMh7kPDhLsI"
Date: Sun, 18 Nov 2018 14:57:23 GMT
Connection: keep-alive

{
  "title": "learn Ansible",
  "author": "albert",
  "id": "21"
}
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100    99  100    66  100    33    282    141 --:--:-- --:--:-- --:--:--   423

In [58]:
!curl  http://localhost:3000/posts/21


{
  "title": "learn Ansible",
  "author": "albert",
  "id": "21"
}
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100    66  100    66    0     0    302      0 --:--:-- --:--:-- --:--:--   302

PATCH (partial update)


In [1]:
!curl -i -X PATCH -d "author=annabella" http://localhost:3000/posts/21


HTTP/1.1 200 OK
X-Powered-By: Express
Vary: Origin, Accept-Encoding
Access-Control-Allow-Credentials: true
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
X-Content-Type-Options: nosniff
Content-Type: application/json; charset=utf-8
Content-Length: 69
ETag: W/"45-QTjOxv2HU/ysRWCKeKoRkFs2otI"
Date: Sun, 18 Nov 2018 17:55:31 GMT
Connection: keep-alive

{
  "title": "learn Ansible",
  "author": "annabella",
  "id": "21"
}
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100    85  100    69  100    16    294     68 --:--:-- --:--:-- --:--:--   363

DELETE


In [71]:
!curl http://localhost:3000/posts


[
  {
    "id": 1,
    "title": "json-server",
    "author": "typicode"
  },
  {
    "id": 3,
    "title": "Docker",
    "author": "shipper"
  },
  {
    "title": "learn Ansible",
    "author": "albert",
    "id": "21"
  },
  {
    "id": 4,
    "title": "apache-server",
    "author": "apache"
  }
]
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   299  100   299    0     0   1277      0 --:--:-- --:--:-- --:--:--  1277

In [70]:
!curl -X DELETE http://localhost:3000/posts/t1FLpvx


{}
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100     2  100     2    0     0      9      0 --:--:-- --:--:-- --:--:--     9

In [61]:
!cat request1.json


{
    "id": 4,
    "title": "apache-server",
    "author": "apache"
}

In [62]:
! curl -vX POST http://localhost:3000/posts -d @request1.json --header "Content-Type: application/json"


{
  "id": 4,
  "title": "apache-server",
  "author": "apache"
}
Note: Unnecessary use of -X or --request, POST is already inferred.
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying ::1...
* TCP_NODELAY set
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 3000 (#0)

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0> POST /posts HTTP/1.1

> Host: localhost:3000

> User-Agent: curl/7.60.0

> Accept: */*

> Content-Type: application/json

> Content-Length: 65

> 

} [65 bytes data]
* upload completely sent off: 65 out of 65 bytes
< HTTP/1.1 201 Created

< X-Powered-By: Express

< Vary: Origin, X-HTTP-Method-Override, Accept-Encoding

< Access-Control-Allow-Credentials: true

< Cache-Control: no-cache

< Pragma: no-cache

< Expires: -1

< Access-Control-Expose-Headers: Location

< Location: http://localhost:3000/posts/4

< X-Content-Type-Options: nosniff

< Content-Type: application/json; charset=utf-8

< Content-Length: 63

< ETag: W/"3f-djA0IQeJe0MNFMZikFGoSll+lcI"

< Date: Sun, 18 Nov 2018 15:07:26 GMT

< Connection: keep-alive

< 

{ [63 bytes data]

100   128  100    63  100    65    288    298 --:--:-- --:--:-- --:--:--   587
* Connection #0 to host localhost left intact

In [63]:
!curl -X GET http://localhost:3000/posts/4


{
  "id": 4,
  "title": "apache-server",
  "author": "apache"
}
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100    63  100    63    0     0    269      0 --:--:-- --:--:-- --:--:--   269

SLICE


In [2]:
!curl -X GET http://localhost:3000/posts


[
  {
    "id": 1,
    "title": "json-server",
    "author": "typicode"
  },
  {
    "id": 3,
    "title": "Docker",
    "author": "shipper"
  },
  {
    "title": "learn Ansible",
    "author": "annabella",
    "id": "21"
  },
  {
    "id": 4,
    "title": "apache-server",
    "author": "apache"
  }
]
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   302  100   302    0     0   1208      0 --:--:-- --:--:-- --:--:--  1208

In [6]:
!curl http://localhost:3000/posts?_start=1&_end=2


[
  {
    "id": 1,
    "title": "json-server",
    "author": "typicode"
  },
  {
    "id": 3,
    "title": "Docker",
    "author": "shipper"
  },
  {
    "title": "learn Ansible",
    "author": "annabella",
    "id": "21"
  },
  {
    "id": 4,
    "title": "apache-server",
    "author": "apache"
  }
]
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   302  100   302    0     0   1378      0 --:--:-- --:--:-- --:--:--  1378
'_end' is not recognized as an internal or external command,
operable program or batch file.

SORT


In [15]:
!curl http://localhost:3000/posts?_sort=id&_order=DESC


[
  {
    "id": 1,
    "title": "json-server",
    "author": "typicode"
  },
  {
    "id": "2",
    "title": "Play with Jenkins",
    "author": "oracle"
  },
  {
    "id": 3,
    "title": "Docker",
    "author": "shipper"
  },
  {
    "id": 4,
    "title": "apache-server",
    "author": "apache"
  },
  {
    "title": "learn Ansible",
    "author": "annabella",
    "id": "21"
  },
  {
    "id": "5",
    "title": "learn Docker Compose",
    "author": "Mei"
  }
]
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   464  100   464    0     0   2128      0 --:--:-- --:--:-- --:--:--  2128
'_order' is not recognized as an internal or external command,
operable program or batch file.

In [15]:
!curl http://localhost:3000/posts?_sort=id&_order=DESC


[
  {
    "id": 1,
    "title": "json-server",
    "author": "typicode"
  },
  {
    "id": "2",
    "title": "Play with Jenkins",
    "author": "oracle"
  },
  {
    "id": 3,
    "title": "Docker",
    "author": "shipper"
  },
  {
    "id": 4,
    "title": "apache-server",
    "author": "apache"
  },
  {
    "title": "learn Ansible",
    "author": "annabella",
    "id": "21"
  },
  {
    "id": "5",
    "title": "learn Docker Compose",
    "author": "Mei"
  }
]
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   464  100   464    0     0   2128      0 --:--:-- --:--:-- --:--:--  2128
'_order' is not recognized as an internal or external command,
operable program or batch file.

In [18]:
!curl http://localhost:3000/posts/2


{
  "id": "2",
  "title": "Play with Jenkins",
  "author": "oracle"
}
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100    69  100    69    0     0    294      0 --:--:-- --:--:-- --:--:--   294

In [11]:
!curl http://localhost:3000/posts?q=Docker


[
  {
    "id": 3,
    "title": "Docker",
    "author": "shipper"
  },
  {
    "id": "5",
    "title": "learn Docker Compose",
    "author": "Mei"
  }
]
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   152  100   152    0     0    649      0 --:--:-- --:--:-- --:--:--   649

In [12]:
!curl http://localhost:3000/posts?q=learn


[
  {
    "title": "learn Ansible",
    "author": "annabella",
    "id": "21"
  },
  {
    "id": "5",
    "title": "learn Docker Compose",
    "author": "Mei"
  }
]
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   164  100   164    0     0    697      0 --:--:-- --:--:-- --:--:--   697

In [19]:
!curl http://localhost:3000/posts?q=21


[
  {
    "title": "learn Ansible",
    "author": "annabella",
    "id": "21"
  }
]
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100    83  100    83    0     0    354      0 --:--:-- --:--:-- --:--:--   354

In [66]:
!curl  http://localhost:3000/comments


[
  {
    "id": 1,
    "body": "json-server",
    "postId": 1
  },
  {
    "id": 2,
    "body": "easy to use",
    "postId": 1
  },
  {
    "id": 4,
    "body": "Docker is fun",
    "postId": 3
  },
  {
    "id": 5,
    "body": "Docker great future",
    "postId": 3
  },
  {
    "id": "6",
    "postId": "4",
    "body": "Apache is powerful"
  }
]
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   348  100   348    0     0   1487      0 --:--:-- --:--:-- --:--:--  1487

In [65]:
!curl -X POST http://localhost:3000/comments -d "id=6&postId=4&body=Apache is powerful"


{
  "id": "6",
  "postId": "4",
  "body": "Apache is powerful"
}
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   101  100    64  100    37    292    168 --:--:-- --:--:-- --:--:--   461

In [13]:
!curl  http://localhost:3000/profile


{
  "name": "typicode"
}
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100    24  100    24    0     0     80      0 --:--:-- --:--:-- --:--:--    80
script='query {
  repositoryOwner(login:\"danbst\") {
    repositories(first: 100) {
      edges {
        node {
          nameWithOwner
          pullRequests(last: 100, states: OPEN) {
            edges {
              node {
                title
                url
                author {
                  login
                }
                labels(first: 20) {
                  edges {
                    node {
                      name
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}'
script="$(echo $script)"

curl -i -H 'Content-Type: application/json' \
   -H "Authorization: bearer ........." \
   -X POST -d "{ \"query\": \"$script\"}" https://api.github.com/graphql