Skip to content

Commit 49e32a7

Browse files
committed
Update quick start example
- More easy to understand example
1 parent edc5a80 commit 49e32a7

1 file changed

Lines changed: 88 additions & 84 deletions

File tree

docs/03-quick-start.md

Lines changed: 88 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2,93 +2,97 @@
22
title: Quick Start
33
---
44

5-
To quickly start, let's try something live online.. [REQ|RES](https://reqres.in) is a hosted demo REST api service. Let's call a simple API endpoint from here.
6-
7-
> First [setup **chkware**](setup).
8-
9-
Go to https://reqres.in, and find there is an endpoint like **_GET_ SINGLE USER** we'll call this API with Chkware. So, follow these steps:
10-
11-
1. Create a file called `User.chk`.
12-
2. Put following content
13-
14-
```yaml
15-
---
16-
request:
17-
url: https://reqres.in/api/users/2
18-
method: GET
19-
```
20-
21-
3. from terminal run following
5+
**Prerequisite**: First [setup **chkware**](setup).
6+
7+
Let's call an API that returns current bitcoin price in USD. Please do following:
8+
9+
- Create a file called `bitcoin-usd.chk`
10+
- Open `bitcoin-usd.chk` file, and add following data
11+
12+
```yaml
13+
---
14+
version: default:http:0.7.2
15+
request:
16+
url: https://api.coinstats.app/public/v1/coins/bitcoin?currency=USD
17+
method: GET
18+
```
19+
20+
- Hit enter after writing following command on terminal
21+
22+
```bash
23+
$ chk http bitcoin-usd.chk
24+
```
25+
26+
- You'll get output like following. Data will vary depending on the day you are doing it.
27+
28+
```bash
29+
File: bitcoin-usd.chk
30+
31+
Executing request
32+
33+
- Making request [Success]
34+
====
35+
HTTP/1.1 200 OK
36+
Content-Type: application/json; charset=utf-8
37+
Content-Length: 510
38+
Connection: keep-alive
39+
Date: Sun, 07 Aug 2022 06:05:23 GMT
40+
X-Powered-By: Express
41+
Access-Control-Allow-Origin: *
42+
ETag: W/"1fe-daabae46"
43+
X-Cache: Miss from cloudfront
44+
Via: 1.1 02d36a84a910749e0e01cf16e7e1a02a.cloudfront.net (CloudFront)
45+
X-Amz-Cf-Pop: SIN5-C1
46+
X-Amz-Cf-Id: es7o2_gllNtjITVD3QM3Y5EH3ASHfg1sjav2o5RSSJKH8Mo3Dv_8BA==
47+
48+
{'coin': {'id': 'bitcoin', 'icon': 'https://static.coinstats.app/coins/1650455588819.png', 'name': 'Bitcoin', 'symbol': 'BTC', 'rank': 1, 'price': 22991.80131938709, 'priceBtc': 1, 'volume': 17847616879.01853, 'marketCap': 439482097425.5293, 'availableSupply': 19114731, 'totalSupply': 21000000, 'priceChange1h': 0.11, 'priceChange1d': -0.92, 'priceChange1w': -3.04, 'websiteUrl': 'http://www.bitcoin.org', 'twitterUrl': 'https://twitter.com/bitcoin', 'exp': ['https://blockchair.com/bitcoin/', 'https://btc.com/', 'https://btc.tokenview.com/']}}
49+
```
50+
51+
- Now If you add `--result` flag to the command: it should show you the raw result output.
52+
53+
```bash
54+
$ chk http --result bitcoin-usd.chk
55+
HTTP/1.1 200 OK
56+
Content-Type: application/json; charset=utf-8
57+
Content-Length: 510
58+
Connection: keep-alive
59+
Date: Sun, 07 Aug 2022 06:10:39 GMT
60+
X-Powered-By: Express
61+
Access-Control-Allow-Origin: *
62+
ETag: W/"1fe-779b4c2b"
63+
X-Cache: Miss from cloudfront
64+
Via: 1.1 14193a789201b44415bebb86f9e5fe9c.cloudfront.net (CloudFront)
65+
X-Amz-Cf-Pop: SIN5-C1
66+
X-Amz-Cf-Id: IodB70Lc4gtw_oinJwEIQnzgu9q-HCW_OCVfiAzYUUgmlrJr9CaiGA==
67+
68+
{'coin': {'id': 'bitcoin', 'icon': 'https://static.coinstats.app/coins/1650455588819.png', 'name': 'Bitcoin', 'symbol': 'BTC', 'rank': 1, 'price': 22981.487132414983, 'priceBtc': 1, 'volume': 17816663920.88816, 'marketCap': 439284944516.0738, 'availableSupply': 19114731, 'totalSupply': 21000000, 'priceChange1h': 0.03, 'priceChange1d': -0.9, 'priceChange1w': -3.09, 'websiteUrl': 'http://www.bitcoin.org', 'twitterUrl': 'https://twitter.com/bitcoin', 'exp': ['https://blockchair.com/bitcoin/', 'https://btc.com/', 'https://btc.tokenview.com/']}}
69+
```
70+
71+
- If you open `bitcoin-usd.chk` change like following, you should only get the API response body.
72+
73+
```yaml
74+
---
75+
version: default:http:0.7.2
76+
request:
77+
url: https://api.coinstats.app/public/v1/coins/bitcoin?currency=USD
78+
method: GET
79+
return: .body # <-- to get body of response
80+
```
81+
82+
```bash
83+
$ chk http --result bitcoin-usd.chk
84+
{'coin': {'id': 'bitcoin', 'icon': 'https://static.coinstats.app/coins/1650455588819.png', 'name': 'Bitcoin', 'symbol': 'BTC', 'rank': 1, 'price': 22981.487132414983, 'priceBtc': 1, 'volume': 17816663920.88816, 'marketCap': 439284944516.0738, 'availableSupply': 19114731, 'totalSupply': 21000000, 'priceChange1h': 0.03, 'priceChange1d': -0.9, 'priceChange1w': -3.09, 'websiteUrl': 'http://www.bitcoin.org', 'twitterUrl': 'https://twitter.com/bitcoin', 'exp': ['https://blockchair.com/bitcoin/', 'https://btc.com/', 'https://btc.tokenview.com/']}}
85+
```
86+
87+
- now we will use `jq` json parser to get price data. [jq website](https://stedolan.github.io/jq/) here.
2288

2389
```bash
24-
$ chk http User.chk
25-
```
26-
27-
See the output like
28-
29-
```text
30-
HTTP/1.1 200 OK
31-
Date: Sat, 29 Jan 2022 16:46:26 GMT
32-
Content-Type: application/json; charset=utf-8
33-
Transfer-Encoding: chunked
34-
...truncated-headers...
35-
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400
36-
37-
{'data': {'id': 2, 'email': 'janet.weaver@reqres.in', 'first_name': 'Janet', 'last_name': 'Weaver', 'avatar': 'https://reqres.in/img/faces/2-image.jpg'}, 'support': {'url': 'https://reqres.in/#support-heading', 'text': 'To keep ReqRes free, contributions towards server costs are appreciated!'}}
38-
```
39-
40-
:wink::tada::confetti_ball:
41-
90+
$ chk http --result bitcoin-usd.chk | jq '.coin.price'
91+
22981.487132414983 # <-- depends on the current value
92+
```
4293
---
94+
We just fetched a live API. You can use `chk http` as your scriptable http client like this :rocket::star2:.
4395

44-
Now let's try a more complex API. Let's call COVID-19 data from RapidAPI. You can call this api for any country with a two letter country code. Let's do the following to fetch covid-19 data for Bangladesh:
45-
46-
1. Register or login to https://rapidapi.com
47-
2. Subscribe to https://rapidapi.com/Gramzivi/api/covid-19-data/ this source.
48-
3. Create a directory called `~/project` and `covid-19.chk` in it
49-
4. Now open `covid-19.chk` file and add following data
50-
51-
```yaml
52-
---
53-
request:
54-
url: https://covid-19-data.p.rapidapi.com/report/country/code
55-
url_params:
56-
code: bd
57-
date: '2020-04-01'
58-
method: GET
59-
headers:
60-
X-RapidAPI-Host: 'covid-19-data.p.rapidapi.com'
61-
X-RapidAPI-Key: '<your X-RapidAPI-Key>'
62-
```
63-
64-
1. hit enter writing following command on terminal
65-
66-
```bash
67-
$ cd ~/project
68-
$ chk http covid-19.chk
69-
```
70-
71-
1. You'll get output like this
72-
73-
```text
74-
HTTP/1.1 200 OK
75-
Cache-Control: no-cache, private
76-
Content-Type: application/json
77-
Date: Sun, 23 Jan 2022 04:28:35 GMT
78-
ETag: "69236d0ee4cbd7e37314028f0a8b01be"
79-
Server: RapidAPI-1.2.8
80-
Vary: Accept
81-
X-RapidAPI-Region: AWS - ap-southeast-1
82-
X-RapidAPI-Version: 1.2.8
83-
X-RateLimit-Requests-Limit: 50000
84-
X-RateLimit-Requests-Remaining: 49988
85-
X-RateLimit-Requests-Reset: 2175151
86-
Content-Length: 182
87-
Connection: keep-alive
88-
89-
[{'country': 'Bangladesh', 'provinces': [{'province': 'Bangladesh', 'confirmed': 54, 'recovered': 25, 'deaths': 6, 'active': 23}], 'latitude': 23.684994, 'longitude': 90.356331, 'date': '2020-04-01'}]
90-
```
96+
Going further, you should save these `.chk` files in git repo, so that you can run it later, from anywhere where **chkware** is installed. Cheers.
9197

9298
:wink::tada::confetti_ball:
93-
94-
You just fetch a live API. Going further, you should save these `.chk` files in git repo, so that you can run it later, from anywhere where **chkware** is installed. Cheers.

0 commit comments

Comments
 (0)