supabase-function-rs
Library
Overview
supabase-function-rs
is a Rust client library designed to interact with Supabase Edge Functions. This library provides a straightforward way to invoke Supabase functions with various HTTP methods, headers, and body types, including JSON, plain text, form data, file uploads, blobs, and array buffers. It also supports setting custom regions for function invocation.
Features
- Invoke Supabase Edge Functions with different HTTP methods.
- Support for various body types: JSON, plain text, form data, file uploads, blobs, and array buffers.
- Custom headers support.
- Region-specific function invocation.
- Comprehensive error handling.
Installation
Add the following to your Cargo.toml
:
[]
= "0.1.0"
Usage
Initialization
To get started, initialize the FunctionsClient
with the Supabase URL and optional headers and region.
use ;
use HashMap;
let url = "https://your-supabase-url";
let mut headers = new;
headers.insert;
let client = new;
client.set_auth;
Basic Function Invocation
use ;
use json;
use HashMap;
let mut invoke_options = default;
invoke_options.method = Some;
let mut json_body = new;
json_body.insert;
invoke_options.body = Some;
match client.invoke.await
Function Invocation with Different Body Types
Plain Text
invoke_options.body = Some;
match client.invoke.await
Form Data
let mut form_data = new;
form_data.insert;
form_data.insert;
invoke_options.body = Some;
match client.invoke.await
File Upload
use File;
use Read;
let path = "test_file.txt";
let mut file = open.unwrap;
let mut file_content = Vec new;
file.read_to_end.unwrap;
invoke_options.body = Some;
match client.invoke.await
Blob
let blob: = vec!; // Example blob data
invoke_options.body = Some;
match client.invoke.await
ArrayBuffer
let array_buffer: = vec!; // Example array buffer data
invoke_options.body = Some;
match client.invoke.await
Setting a Custom Region
You can specify a custom region when invoking a function:
invoke_options.region = Some;
match client.invoke.await
Error Handling
The library provides comprehensive error handling with specific error types:
FunctionsFetchError
: Indicates a failure to send the request.FunctionsRelayError
: Indicates a relay error when invoking the function.FunctionsHttpError
: Indicates a non-2xx status code returned by the function.
Example:
match client.invoke.await
Testing
To run the tests, use:
Contributing
Feel free to open issues or submit pull requests for new features, bug fixes, or improvements.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Acknowledgements
Special thanks to the contributors and the open-source community for their support and contributions.