https://www.baeldung.com/curl-rest
https://jsonplaceholder.typicode.com/ is a great REST API test site
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
In [2]:
!cat todos-1.json
In [4]:
! curl https://jsonplaceholder.typicode.com/photos/1
In [5]:
! curl "https://jsonplaceholder.typicode.com/users/10"
In [7]:
! curl "https://jsonplaceholder.typicode.com/users/id=10&username=Moria.Stanley"
In [8]:
! curl "https://jsonplaceholder.typicode.com/users/10"
In [9]:
! curl -X DELETE https://jsonplaceholder.typicode.com/users/10
In [10]:
!curl https://jsonplaceholder.typicode.com/users/10
https://github.com/typicode/json-server
$ npm install -g json-server
$ json-server --watch db.json
In [20]:
!curl http://localhost:3000/db
In [55]:
!curl http://localhost:3000/posts
In [49]:
! curl -X POST -d "id=21&title=learn JSON&author=gong" http://localhost:3000/posts/
In [10]:
! curl -X POST -d "id=5&title=learn Docker Compose&author=Mei" http://localhost:3000/posts/
In [14]:
! curl -X POST -d "id=2&title=Play with Jenkins&author=oracle" http://localhost:3000/posts/
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"
In [53]:
!curl -X PUT -d "id=21&title=learn REST&author=wen" http://localhost:3000/posts/21
In [57]:
!curl -i -X PUT -d "title=learn Ansible&author=albert" http://localhost:3000/posts/21
In [58]:
!curl http://localhost:3000/posts/21
In [1]:
!curl -i -X PATCH -d "author=annabella" http://localhost:3000/posts/21
In [71]:
!curl http://localhost:3000/posts
In [70]:
!curl -X DELETE http://localhost:3000/posts/t1FLpvx
In [61]:
!cat request1.json
In [62]:
! curl -vX POST http://localhost:3000/posts -d @request1.json --header "Content-Type: application/json"
In [63]:
!curl -X GET http://localhost:3000/posts/4
In [2]:
!curl -X GET http://localhost:3000/posts
In [6]:
!curl http://localhost:3000/posts?_start=1&_end=2
In [15]:
!curl http://localhost:3000/posts?_sort=id&_order=DESC
In [15]:
!curl http://localhost:3000/posts?_sort=id&_order=DESC
In [18]:
!curl http://localhost:3000/posts/2
In [11]:
!curl http://localhost:3000/posts?q=Docker
In [12]:
!curl http://localhost:3000/posts?q=learn
In [19]:
!curl http://localhost:3000/posts?q=21
In [66]:
!curl http://localhost:3000/comments
In [65]:
!curl -X POST http://localhost:3000/comments -d "id=6&postId=4&body=Apache is powerful"
In [13]:
!curl http://localhost:3000/profile
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