Readme

tldraw computer custom endpoint example

This val is an example custom endpoint for tldraw computer's data component.

Usage

To use this val with tldraw.computer, follow these steps:

  1. Fork this Val.
  2. Click the Copy endpoint button on your new Val.
  3. Open a project on tldraw.computer
  4. Create a Data component in your tldraw computer project
  5. In the Source dropdown, select Custom and the POST method
  6. Paste the endpoint into Data component's the HTTP Endpoint input.
  7. Run the component.

To see the output, connect the Data component to a Text component.

How it works

In tldraw computer, you can configure a Data component to use a custom HTTP endpoint as its data source. You can also configure the request method, either GET or POST.

If a Data component's request method is POST, then when the component next updates, it will send a POST request to the endpoint. The request's body will contain an array of the Data objects that the component had received as inputs.

If the request method if GET, then the component will only make the request—its body will be empty.

In both cases, the component will expect back a response that includes an array of Data objects these objects will be passed along as the data component's outputs.

The endpoint (your forked version of this Val) can do whatever it likes between the request and response, but the response must include data in the correct format. If the format is wrong, the computer app will create a text data object instead that includes the response as plain text.

Support

If you're running into any difficulties, check out the #tldraw-computer channel on the tldraw discord.

Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
ni5k0-tldraw_computer_example.web.val.run
Updated: December 21, 2024