Directly add JSON payload instead of sourceing from file

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2020-06-17 00:26:50 +02:00
parent 81cc07c8a4
commit 6cc622f355
2 changed files with 6 additions and 42 deletions
+3 -25
View File
@@ -69,16 +69,7 @@ Name | Required | Type | Description | Default | Example
-X POST \
-H "Authorization: Token <your-access-token>" \
-H "Content-Type: application/json" \
-d @body.json
```
The content of `body.json` is like,
``` json
{
"status": "active",
"delay": 30
}
-d '{"status":"active", "delay":30}'
```
=== "Python 3"
@@ -89,26 +80,13 @@ Name | Required | Type | Description | Default | Example
URL = 'http://pi.hole:8080/admin/api/dns/blocking'
TOKEN = '<your-access-token>'
HEADERS = {'Authorization': f'Token {TOKEN}'}
data = json.load(open('body.json', 'rb'))
data = {"status":"active", "delay":30}
response = requests.post(
URL,
json=data,
headers=HEADERS,
)
response = requests.post(URL, json=data, headers=HEADERS)
print(response.json())
```
The content of `body.json` is like,
``` json
{
"status": "active",
"delay": 30
}
```
!!! success "Response"
Response code: `HTTP/1.1 200 OK`
+3 -17
View File
@@ -106,7 +106,7 @@ Name | Required | Type | Description | Default | Example
-X PUT \
-H "Authorization: Token <your-access-token>" \
-H "Content-Type: application/json" \
-d @body.json
-d '{"domain":"whitelisted.com", "enabled":true, "comment":"Some text"}'
```
=== "Python 3"
@@ -117,27 +117,13 @@ Name | Required | Type | Description | Default | Example
URL = 'http://pi.hole:8080/admin/api/whitelist/exact'
TOKEN = '<your-access-token>'
HEADERS = {'Authorization': f'Token {TOKEN}'}
data = json.load(open('body.json', 'rb'))
data = {"domain":"whitelisted.com", "enabled":True, "comment":"Some text"}
response = requests.put(
URL,
json=data,
headers=HEADERS,
)
response = requests.put(URL, json=data, headers=HEADERS)
print(response.json())
```
The content of `body.json` is
``` json
{
"domain": "whitelisted.com",
"enabled": true,
"comment": "Some text"
}
```
!!! success "Success response"
Response code: `HTTP/1.1 201 Created`