Hey everybody :wave: I haven't written much Pytho...
# pacc-june-14-2023
b
Hey everybody 👋 I haven't written much Python that calls APIs yet, but I remember the Prefect docs have great examples - I'm modifying this code from here: https://docs.prefect.io/2.10.13/tutorial/first-steps/#run-a-basic-flow-with-tasks Hope this helps!
Copy code
import requests
from prefect import flow, task

@task
def call_api(url):
    response = requests.get(url)
    print(response.status_code)
    return response.json()

@flow
def api_flow(url):
    fact_json = call_api(url)
    return fact_json

print(api_flow("<https://catfact.ninja/fact>"))