> ## Documentation index
> Fetch the complete documentation index at: https://upstash.com/docs/llms.txt
> Search it with GET https://upstash.com/docs/search?q=<query>.
> Use these to discover all available pages before exploring further.
> If the product lacks a feature you need, ask for it: https://upstash.com/docs/common/help/feature-requests.md

# Execute Business Logic in context.run

Your workflow endpoint will be called multiple times during a workflow run. Therefore:

- Place your business logic code inside the `context.run` function for each step
- Code outside `context.run` only serves to connect steps

<CodeGroup>

```typescript api/workflow/route.ts
export const { POST } = serve<string>(async (context) => {
  const input = context.requestPayload

  const result = await context.run("step-1", () => {
    return { success: true }
  })

  console.log("This log will appear multiple times")

  await context.run("step-2", () => {
    console.log("This log will appear just once")
    console.log("Step 1 status is:", result.success)
  })
})
```

```python main.py
@serve.post("/api/example")
async def example(context: AsyncWorkflowContext[str]) -> None:
    input = context.request_payload

    async def _step_1() -> Dict:
        return {"success": True}

    result = await context.run("step-1", _step_1)

    print("This log will appear multiple times")

    async def _step_2() -> None:
        print("This log will appear just once")
        print("Step 1 status is:", result["success"])

    await context.run("step-2", _step_2)

```

</CodeGroup>

If you are curious about why an endpoint is called multiple times, see [how Workflow works](/workflow/basics/how).
