Space Operator
  • Welcome
  • Visual Builder
    • Flows
      • API Key & POST Request
      • WebSocket
        • Signature Requests
      • Nested Flows
      • Learn Solana
      • Add flows to your websites
      • Iterate with Localhost
    • Nodes
      • Web Assembly Nodes
        • space-cli
        • space-lib
        • Examples in Rust
          • Rectangle
          • Filter
          • Regex
        • Uploading WASM binary via UI
      • Native Nodes
        • Code Template
        • Node Definition
        • ValueSet
        • Submitting Native Nodes
        • Tracing
      • Mock Nodes
      • JS Node
      • API Input Node
  • Self-hosting
    • Docker Compose
    • Serving HTTPS
    • Lightsail Instance
    • Export data to your instance
  • FAQ
    • Servers
  • References
    • Flows
    • Flow Deployment
Powered by GitBook
On this page

Was this helpful?

  1. Visual Builder
  2. Nodes
  3. Web Assembly Nodes

space-lib

Documentation for how to use space-lib

Previousspace-cliNextExamples in Rust

Last updated 2 years ago

Was this helpful?

space-lib is a crate that abstracts the low level details of calling our custom host functions and includes some nice helper functions. The crate is located here: .

It currently includes a HTTP client that is used for sending requests and receiving responses to websites.

HTTP Client

use space_lib::Request;
 
let body = Request::get("https://www.spaceoperator.com")
    .call()?
    .into_string()?;

There are multiple ways to create a Request, and get is one of them. There's also post, delete, head, patch and put. To set a header field, use the set method like so:

use space_lib::Request;
 
let body = Request::get("https://www.spaceoperator.com")
    .set("Authorization", "Bearer 12345")?;

For setting a query field, use the query method. To send any data with the request, use any of these methods: send_bytes, send_string, send_form and send_json. Note that the type need to implement serde::Serialize to be able to serialize them into json.

After creating the , use the call method. This will call the request on the host system where the Web Assembly is running. After this, you will get a .

There are three methods that can be called on : into_vec which returns Vec<u8>, into_string which returns Result<String> and into_json which returns Result<T> where T: serde::DeserializeOwned.

docs.rs/space-lib
Request
Response
Response