Hi there! I really appreciate your help concerning...
# ask-community
j
Hi there! I really appreciate your help concerning fetch data from Web APIs, in Airflow I understand this can be done via HTTPSensor, HttpOperator... so, what it would be the equivalent in Prefect?, thanks in advance!
n
hi @Javier Buitrago - we don't have a specific prebuilt task for making http requests you could implement a task that does this pretty simply with an http client like
httpx
Copy code
import httpx
from prefect import flow, task

@task
def http_request(method, url, **kwargs):
    with httpx.Client() as client:
        response = client.request(method, url, **kwargs)
        return response.json()

@flow(log_prints=True)
def web_flow():
    data = http_request("GET", "<https://jsonplaceholder.typicode.com/todos/1>")
    print(data)

if __name__ == "__main__":
    web_flow()
🙌 1
did you have something more specific in mind?
j
thank you for your help @Nate!, yes I have a similar code but I was thinking I was missing something about fetch API data,,,
n
is
fetch API data
something specific you're talking about or do you just mean fetching data from some API? if the latter, you could replace the
httpx
call with a call to your API of interest
j
yes Nate, is the last option you say... I need fetch data from an API, which has several security restrictions...
n
cool! let me know if you need any more help implementing your task in a way that respects your restrictions!
j
thank you @Nate!