Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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
```