langflow icon indicating copy to clipboard operation
langflow copied to clipboard

Improve JavaScript API Code Snippet in Modal

Open edwinjosechittilappilly opened this issue 4 months ago • 1 comments

Feature Request

The current JavaScript code snippet in the API modal is not an ideal example of how our developers would typically write or use JavaScript, especially when compared to the curl snippet. A more equivalent and intuitive snippet would fetch data from the network using fetch rather than employing a client.

Suggested Solution:

Please update the JavaScript code snippet in the modal to align more closely with the curl snippet. A suggested code would look something like this:

fetch("https://api.langflow.astra.datastax.com/lf/7436dcd2-a480-4009-bce2-43ba959692e5/api/v1/run/5a232ac1-df88-478e-ad90-be6a98ae08a2?stream=false", {
  method: "POST",
  headers: {
    Authorization: <TOKEN>,
  },
  body: JSON.stringify({}), // Add body data if needed
})
  .then(res => res.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

Motivation

Additional Feedback: 1. The Python API snippet faces a similar issue as it tries to illustrate a “main” that is not reflective of real-world usage in most server cases. 2. The current curl syntax is manually copied and transposed to JavaScript, which still contains issues and could be improved. 3. A suggestion was made to create an npm package that simplifies handling API requests, including both streaming and non-streaming options. This could provide a more cohesive and streamlined experience for developers.

cc: @philnash @mieslep

Your Contribution

No response

edwinjosechittilappilly avatar Oct 14 '24 21:10 edwinjosechittilappilly