is there an easy way to expose the flow as a rest ...
# ask-community
v
is there an easy way to expose the flow as a rest api/webhook that accepts the deployment parameters and executes the flow?
b
Hi Victor! Just to clarify, are you wanting to pass data from a webhook request as parameters to the flow run? Or are you just looking for a way to kick off a flow run adhoc from the Prefect UI, and pass in a set of parameters as input?
v
wanting to execute the flow and want to pass it params. webhooks withe events seems confusing to setup using prefect yaml. I am using yaml for the deployments.
b
Since you're using a prefect.yaml, you'll want to make sure that you have
parameters
defined under the deployment declaration. It'll look something like this:
Copy code
deployments:
  - name: insert-deployment-name-here
    entrypoint: flows/hello.py:my_flow
    parameters:
        number: 42,
        message: Don't panic!
    work_pool:
        name: my-process-work-pool
Once your prefect.yaml is ready, running the following command will create a new deployment record in the "Deployments" page Prefect UI:
prefect deploy --name insert-deployment-name-here
When you preview your new deployment from the UI, you'll see a "Run" button in the upper right-hand corner with a "Custom Run" option. From there, you can pass in any custom values you'd like as input, and then kick off a new run of your flow.
IMO, aside from the
prefect.yaml
file, the quickest way to create a deployment with parameters would be the
.serve()
method, which looks like this:
Copy code
from prefect import flow

@flow(log_prints=True)
def hello_world(name: str = "world", goodbye: bool = False):
    print(f"Hello {name} from Prefect! :hugging_face:")
    
    if goodbye:
        print(f"Goodbye {name}!")

if __name__ == "__main__":
    hello_world.serve(
        name="my-first-deployment",
        tags=["onboarding"],
        parameters={"goodbye": True},
        interval=60
    )
When you run this script, it will create a deployment and start a long-running process that listens for new work. You can do the same thing where you go to the Prefect UI, navigate to the Deployment page, and select the "Custom Run" option to pass inputs to the flow.