Skip to content

Request: better docs how to integrate other platforms #127

@alexbepple

Description

@alexbepple

The docs are pretty minimalistic on how to integrate other platforms: https://upstash.com/docs/workflow/quickstarts/platforms#using-workflow-with-another-platform

I had to dig through one of the existing integrations in order to understand what I need to do in order to integrate with AWS Lambda. I did not particularly love the experience.

It would be great, if you could extend the existing docs and explain what one needs to do.

My understanding is that the following represents the bare minimum for integrating a platform. You might find this helpful as a starting point for amending the docs:

import { serve } from '@upstash/workflow'

const getExternallyReachableUrlOfWorkflow = (request) => 'https://…'

const map2UpstashWorkflowRequest = (request) => {
  return new Request(getExternallyReachableUrlOfWorkflow(request), {
    // pseudocode; the format of `request` is defined by your HTTP framework/gateway
    method: request.method,
    body: request.rawBody, // must be stringified JSON
    headers: new Headers(request.headers),
  })
}

const mapUpstashWorkflowResponse = async (wfResponse) => ({
  // pseudocode; the return format is defined by your HTTP framework/gateway
  status: wfResponse.status,
  headers: Object.fromEntries(wfResponse.headers),
  json: await wfResponse.json(),
})

export const runWorkflow = (workflowFunction) => async (request) =>
  runPromiseAwarePipe(
    request,
    map2UpstashWorkflowRequest,
    (wfRequest) => serve(workflowFunction, { useJSONContent: true }).handler(wfRequest),
    mapUpstashWorkflowResponse,
  )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions