Skip to content

Commit e2db36f

Browse files
committed
Update readme
1 parent 04a5d4f commit e2db36f

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# api-test
2+
3+
A simple bash script to test JSON API from terminal in a structured and organized way.
4+
5+
## Setting up
6+
7+
### Requirements
8+
9+
- [curl](https://curl.haxx.se/download.html)
10+
- [jq](https://stedolan.github.io/jq/download)
11+
12+
## Installing
13+
14+
```
15+
curl https://raw.githubusercontent.com/subeshb1/api-test/master/api-test.sh
16+
```
17+
18+
### Alternate Approach
19+
20+
Since it is a small bash file, you can copy the content in https://raw.githubusercontent.com/subeshb1/api-test/master/api-test.sh and paste in a file, make it executable and run it.
21+
22+
## Usage
23+
24+
```sh
25+
$ api-test.sh -h
26+
27+
USAGE: api-test [-hv] [-f file_name] [CMD] [ARGS]
28+
29+
OPTIONS:
30+
-h (--help) print this message
31+
-h (--help) print this message
32+
-v (--verbose) verbose logging
33+
-f (--file) file to test
34+
35+
COMMANDS:
36+
run Run test cases specified in the test file.
37+
Example: 'api-test -f test.json run test_case_1 test_case_2', 'api-test -f test.json run all'
38+
```
39+
40+
### Test file
41+
42+
The test file will contain test cases in json format.
43+
44+
Example:
45+
`test.json`
46+
47+
```json
48+
{
49+
"name": "My API test",
50+
"testCases": {
51+
"test_case_1": {
52+
"path": "/path_1",
53+
"method": "POST",
54+
"description": "Best POST api",
55+
"body": {
56+
"value": 1
57+
},
58+
"header": {
59+
"X-per": "1"
60+
}
61+
},
62+
"test_case_2": {
63+
"path": "/path_2",
64+
"method": "GET",
65+
"description": "Best GET api",
66+
"query": {
67+
"value": 1
68+
}
69+
},
70+
"test_case_3": {
71+
"path": "/path_1",
72+
"method": "DELETE",
73+
"description": "Best DELETE api",
74+
"body": {
75+
"value": 1
76+
}
77+
}
78+
},
79+
"url": "localhost:3000",
80+
"header": {
81+
"Authorization": "Bearer <ACCESS_TOKEN>"
82+
}
83+
}
84+
```
85+
86+
The test cases are present in the `testCases` object. The main url for the api is store in `url` string. If the test cases share common headers add them in root `header` key.
87+
88+
### Running test case
89+
90+
```
91+
api-test -f test.json run test_case_1 # running single test case
92+
api-test -f test.json run test_case_1 test_case_2 # running multiple test case
93+
api-test -f test.json run all # running all test case. WARNING: Don't name a test case `all`
94+
```

0 commit comments

Comments
 (0)