Skip to content

Commit 3b1c74d

Browse files
committed
update examples, update api_nested docs
1 parent e767a8e commit 3b1c74d

29 files changed

+603
-493
lines changed

docs/http_snippets/README.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,29 @@ npm install --global httpsnippet
1313
npm install --save httpsnippet
1414
```
1515

16+
## Spec
17+
18+
Create HAR specs (.json files) in this directory.
19+
20+
> **Don't edit any files in the `./snippets` directory manually!**
21+
1622
## Generate
1723

1824
### Create all snippets and run requests for them
1925

2026
```shell
21-
# run and create for all
22-
./run_and_create.sh
27+
# run and create for all minimal api requests
28+
./run_and_create.sh minimal_api
29+
```
30+
31+
```shell
32+
# run and create for all nested api requests
33+
./run_and_create.sh nested_api
34+
```
35+
36+
```shell
37+
# run and create for delete example nested api requests
38+
./run_and_create.sh nested_api__delete
2339
```
2440

2541
### Or do it manually:
@@ -54,8 +70,20 @@ httpsnippet ./*.json --target python --client requests --output ./snippets
5470
```
5571

5672
```shell
57-
# Run requests, save output
58-
python3 update_snippets_with_responses.py
73+
# Run requests for minimal api, save output
74+
python3 update_snippets_with_responses.py minimal_api
75+
```
76+
77+
```shell
78+
# Run requests for nested api, save output
79+
python3 update_snippets_with_responses.py nested_api
80+
```
81+
82+
#### Verbose logs (DEBUG level)
83+
84+
```shell
85+
# Run requests for nested api, save output
86+
python3 update_snippets_with_responses.py nested_api --verbose
5987
```
6088

6189
> **Pro tip:** run webserver for specs before running update_snippets_with_responses, otherwise it won't work 😉
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"method": "POST",
3+
"url": "http://localhost:5000/computers",
4+
"httpVersion": "HTTP/1.1",
5+
"queryString": [
6+
],
7+
"headers": [
8+
{
9+
"name": "content-type",
10+
"value": "application/vnd.api+json"
11+
}
12+
],
13+
"postData": {
14+
"mimeType": "application/json",
15+
"text": "{\n \"data\": {\n \"type\": \"computer\",\n \"attributes\": {\n \"serial\": \"Amstrad\"\n }\n }\n}"
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"method": "POST",
3+
"url": "http://localhost:5000/persons/1/relationships/computers",
4+
"httpVersion": "HTTP/1.1",
5+
"queryString": [
6+
],
7+
"headers": [
8+
{
9+
"name": "content-type",
10+
"value": "application/vnd.api+json"
11+
}
12+
],
13+
"postData": {
14+
"mimeType": "application/json",
15+
"text": "{\n \"data\": [\n {\n \"type\": \"computer\",\n \"id\": \"4\"\n }\n ]\n}"
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"method": "POST",
3+
"url": "http://localhost:5000/persons?include=computers",
4+
"httpVersion": "HTTP/1.1",
5+
"queryString": [
6+
],
7+
"headers": [
8+
{
9+
"name": "content-type",
10+
"value": "application/vnd.api+json"
11+
}
12+
],
13+
"postData": {
14+
"mimeType": "application/json",
15+
"text": "{\n \"data\": {\n \"type\": \"person\",\n \"attributes\": {\n \"name\": \"John\",\n \"email\": \"john@exmple.com\"\n },\n \"relationships\": {\n \"computers\": {\n \"data\": [\n {\n \"type\": \"computer\",\n \"id\": \"2\"\n }\n ]\n }\n }\n }\n}"
16+
}
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"method": "DELETE",
3+
"url": "http://localhost:5000/computers/1",
4+
"httpVersion": "HTTP/1.1",
5+
"queryString": [
6+
],
7+
"headers": [
8+
{
9+
"name": "content-type",
10+
"value": "application/vnd.api+json"
11+
}
12+
]
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"method": "DELETE",
3+
"url": "http://localhost:5000/persons/1/relationships/computers",
4+
"httpVersion": "HTTP/1.1",
5+
"queryString": [
6+
],
7+
"headers": [
8+
{
9+
"name": "content-type",
10+
"value": "application/vnd.api+json"
11+
}
12+
],
13+
"postData": {
14+
"mimeType": "application/json",
15+
"text": "{\n \"data\": [\n {\n \"type\": \"computer\",\n \"id\": \"3\"\n }\n ]\n}"
16+
}
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"method": "GET",
3+
"url": "http://localhost:5000/computers",
4+
"httpVersion": "HTTP/1.1",
5+
"queryString": [
6+
],
7+
"headers": [
8+
{
9+
"name": "content-type",
10+
"value": "application/vnd.api+json"
11+
}
12+
]
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"method": "PATCH",
3+
"url": "http://localhost:5000/computers/1",
4+
"httpVersion": "HTTP/1.1",
5+
"queryString": [
6+
],
7+
"headers": [
8+
{
9+
"name": "content-type",
10+
"value": "application/vnd.api+json"
11+
}
12+
],
13+
"postData": {
14+
"mimeType": "application/json",
15+
"text": "{\n \"data\": {\n \"type\": \"computer\",\n \"id\": \"1\",\n \"attributes\": {\n \"serial\": \"New Amstrad\"\n }\n }\n}"
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"method": "PATCH",
3+
"url": "http://localhost:5000/persons/1?include=computers",
4+
"httpVersion": "HTTP/1.1",
5+
"queryString": [
6+
],
7+
"headers": [
8+
{
9+
"name": "content-type",
10+
"value": "application/vnd.api+json"
11+
}
12+
],
13+
"postData": {
14+
"mimeType": "application/json",
15+
"text": "{\n \"data\": {\n \"type\": \"person\",\n \"id\": \"1\",\n \"attributes\": {\n \"email\": \"john@example.com\"\n },\n \"relationships\": {\n \"computers\": {\n \"data\": [\n {\n \"type\": \"computer\",\n \"id\": \"3\"\n }\n ]\n }\n }\n }\n}"
16+
}
17+
}
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
#!/usr/bin/env sh
1+
#!/usr/bin/env bash
22

3-
echo "Create HTTP snippets"
4-
httpsnippet ./*.json --target http --output ./snippets
3+
echo "Create HTTP and Python snippets"
54

6-
echo "Create Python (requests) snippets"
7-
httpsnippet ./*.json --target python --client requests --output ./snippets
5+
for filename in ./"$1"*.json; do
6+
echo "process $filename"
7+
httpsnippet "$filename" --target http --output ./snippets
8+
httpsnippet "$filename" --target python --client requests --output ./snippets
9+
done
810

911
echo "Run requests"
10-
python3 update_snippets_with_responses.py
12+
python3 update_snippets_with_responses.py "$1"

0 commit comments

Comments
 (0)