Skip to content

Commit

Permalink
json.dumps() output from cli, call raise_for_status on results, make …
Browse files Browse the repository at this point in the history
…a get request if no parameters included in cli call
  • Loading branch information
g-simmons committed Aug 9, 2024
1 parent cd616f5 commit c01bbe0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions papercast/scripts/papercast.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import sys
import requests
import json


def call_api(endpoint, params):
print(f"Calling {endpoint} with parameters {params}.")
base_url = "http://localhost:8000"
print(f"{base_url}/{endpoint}")
response = requests.post(f"{base_url}/{endpoint}", json=params)
if params:
response = requests.post(f"{base_url}/{endpoint}", json=params)
else:
response = requests.get(f"{base_url}/{endpoint}")
response.raise_for_status()
return response.json()


Expand Down Expand Up @@ -42,7 +47,7 @@ def parse_arguments():
def main():
endpoint, params = parse_arguments()
response = call_api(endpoint, params)
print(response)
print(json.dumps(response))


if __name__ == "__main__":
Expand Down

0 comments on commit c01bbe0

Please sign in to comment.