Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tbillington/rust_serverless_runtime
A serverless runtime in 200 lines atop deno and sqlite
https://github.com/tbillington/rust_serverless_runtime
deno rust serverless sqlite v8
Last synced: 3 months ago
JSON representation
A serverless runtime in 200 lines atop deno and sqlite
- Host: GitHub
- URL: https://github.com/tbillington/rust_serverless_runtime
- Owner: tbillington
- License: mit
- Created: 2022-09-13T10:33:12.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-09-16T08:50:41.000Z (over 2 years ago)
- Last Synced: 2024-05-21T12:09:38.488Z (8 months ago)
- Topics: deno, rust, serverless, sqlite, v8
- Language: Rust
- Homepage:
- Size: 34.2 KB
- Stars: 127
- Watchers: 6
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
This repo is a demonstration of how you could build your own "serverless" platform with data persistence in only 200~ lines of simple, safe code.
It combines [deno](https://deno.land/) (rust v8 runtime), [axum](https://github.com/tokio-rs/axum/) (http library), and [rusqlite](https://github.com/rusqlite/rusqlite) (sqlite) to build a Function as a Service (FaaS)-like application with file-system backed storage.
A user submits javascript code with a HTTP POST request, then is able to invoke their function via GET requests.
The js environment the code is executed within has access to 3 operations implemented in rust. `console.log` emits messages via stdout on the server, `set` inserts into a sqlite backed key-value store, and `get` retrieves from the same store.
The last evaluated expression from an invoked js function will be returned in the HTTP GET response body.
### Example
https://user-images.githubusercontent.com/2771466/190379404-8c45ff20-c7f9-4215-b18a-cd3926bc0e1f.mov
In your first terminal
```
cargo run
```In your second terminal
```bash
# Submit the contents of fn.js as the function "raccoon"
curl -d @fn.js localhost:8080/fn/raccoon# Invoke the function by it's name
curl localhost:8080/fn/raccoon# And a couple more times... just in case
curl localhost:8080/fn/raccoon
curl localhost:8080/fn/raccoon
curl localhost:8080/fn/raccoon
```