Skip to content

Crud api to store data in memory or database or call an api to store the data #554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
bhumirjhaveri opened this issue Apr 10, 2025 · 7 comments

Comments

@bhumirjhaveri
Copy link

What is the question:
I want to use serverless workflow which is a crud api which will either store data in memory or db or call an another api, how can I do that with sdk-java version 7.0.0 or serverless specs 1?

@bhumirjhaveri
Copy link
Author

We need more examples with 7.0.0 as action, state, functionref etc have been taken of and how to execute workflow correctly?

@fjtirado
Copy link
Collaborator

fjtirado commented Apr 14, 2025

I feel the issue you wrote is more related with the specification than with the java SDK. New DSL extension mechanism to invoke custom APIs is described here

Anyway, since you asked for more examples of how to do things with the new DSL , please take a look to these ones https://github.com/serverlessworkflow/sdk-java/tree/main/impl/core/src/test/resources and https://github.com/serverlessworkflow/sdk-java/tree/main/impl/http/src/test/resources

@bhumirjhaveri
Copy link
Author

Thanks for responding, so idea here is to specify the whole workflow in the specs yaml and from java/language, just start the workflow?

@fjtirado
Copy link
Collaborator

fjtirado commented Apr 15, 2025

There are different things:

  • The Serverless Workflow 1.0 spec, that specifies how to write workflows in yaml or json.
  • The Serverless Worfklow 1.0 Java SDK, that allows you to load an in memory representation of that yaml/json
  • The Serverless Workflow 1.0 Java reference implementation, that use the Java SDK to execute sample workflows written in yaml/json as per specification.

Your original question pertains to the specification domain: "how do I write a workflow that call a CURD API?". Since this functionality is not natively supported by the spec, I referred you to the extension mechanism (which is currently not supported by the reference implementation)

@bhumirjhaveri
Copy link
Author

bhumirjhaveri commented Apr 16, 2025

Thanks!
I am looking for 2nd option to use java-sdk. Load the yaml, have CRUD api and based on api call, perform respective workflow from the yaml.

@bhumirjhaveri
Copy link
Author

bhumirjhaveri commented Apr 16, 2025

Here is what I am thinking

document:
dsl: '1.0.0'
namespace: test
name: switch-example
version: '0.1.0'
use:
functions:
saveToolToDatabase:
input:
schema:
document:
type: object
properties:
toolId:
type: string
toolName:
type: string
toolDescription:
type: string
required: [toolId, toolName]
call: internal
with:
function: storeToolData

do:

  • handle-request:
    switch:
    - create-tool:
    when: .callType == "create-tool"
    then: saveTool
    - update-tool:
    when: .callType == "update-tool"
    then: saveTool
    - default:
    then: handleUnknownOrderType
  • saveTool:
    call: saveToolToDatabase
    with:
    toolId: "tool-1"
    toolName: "sample tool"
    toolDescription: "sample desc"
    then: end
  • end: # End of workflow

saveToolToDatabase should be some java function where I actually write it to underlying database.

Let me know if this is currently supported or not. If not then is there a way out to implement this??

@fjtirado
Copy link
Collaborator

fjtirado commented Apr 22, 2025

@bhumirjhaveri Can you ask the question in the specification repo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants