httpbin & httpie
Using httpbin (HTTP Request & Response Service) we can create easly working HTTP service e.g. for local development. Just pull Docker image and run it on your machine:
docker pull kennethreitz/httpbin
docker run -p 80:80 kennethreitz/httpbin
To query HTTP service you can use several tools like curl
or Postman
. If you want to try something new, then maybe it’s goot to use httpie
, which on macOS can be installed by brew:
brew install httpie
To send request we can reuse existing examples:
> http :80/ip
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 29
Content-Type: application/json
Date: Fri, 10 Dec 2021 16:14:29 GMT
Server: gunicorn/19.9.0
{
"origin": "172.17.0.1"
}
> http :80/headers
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 178
Content-Type: application/json
Date: Fri, 10 Dec 2021 16:14:38 GMT
Server: gunicorn/19.9.0
{
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
"Host": "localhost",
"User-Agent": "HTTPie/2.6.0"
}
}
> http PUT :80/put X-API-Token:123 name=John
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 478
Content-Type: application/json
Date: Fri, 10 Dec 2021 16:19:20 GMT
Server: gunicorn/19.9.0
{
"args": {},
"data": "{\"name\": \"John\"}",
"files": {},
"form": {},
"headers": {
"Accept": "application/json, */*;q=0.5",
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
"Content-Length": "16",
"Content-Type": "application/json",
"Host": "localhost",
"User-Agent": "HTTPie/2.6.0",
"X-Api-Token": "123"
},
"json": {
"name": "John"
},
"origin": "172.17.0.1",
"url": "http://localhost/put"
}
> http -f POST :80/post hello=World
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 444
Content-Type: application/json
Date: Fri, 10 Dec 2021 16:20:04 GMT
Server: gunicorn/19.9.0
{
"args": {},
"data": "",
"files": {},
"form": {
"hello": "World"
},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
"Content-Length": "11",
"Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
"Host": "localhost",
"User-Agent": "HTTPie/2.6.0"
},
"json": null,
"origin": "172.17.0.1",
"url": "http://localhost/post"
}