{"id":17543200,"url":"https://github.com/shonenada/lego","last_synced_at":"2025-10-29T20:45:11.287Z","repository":{"id":66202967,"uuid":"242808772","full_name":"shonenada/lego","owner":"shonenada","description":"A serverless server with wasmer and WebAssembly","archived":false,"fork":false,"pushed_at":"2020-09-23T16:14:58.000Z","size":63,"stargazers_count":13,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-23T23:48:54.752Z","etag":null,"topics":["rust","rust-lang","serverless","wasmer","webassembly"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shonenada.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-24T18:16:28.000Z","updated_at":"2024-08-28T19:25:02.000Z","dependencies_parsed_at":"2023-03-06T20:45:44.931Z","dependency_job_id":null,"html_url":"https://github.com/shonenada/lego","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shonenada%2Flego","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shonenada%2Flego/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shonenada%2Flego/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shonenada%2Flego/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shonenada","download_url":"https://codeload.github.com/shonenada/lego/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250535108,"owners_count":21446506,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rust","rust-lang","serverless","wasmer","webassembly"],"created_at":"2024-10-21T00:23:15.336Z","updated_at":"2025-10-29T20:45:06.251Z","avatar_url":"https://github.com/shonenada.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"Lego\n====\n\nLego is a serverless service with [WebAssembly](https://webassembly.org/) and [wasmer](https://wasmer.io).\n\n\n## Quick Guide\n\n### Prepare wasm\n\n1. Write your wasm in any language you like, in AssemblyScript for example:\n\n```js\nexport function helloWorld() {\n    return \"Hello, Lego\";\n}\n```\n\n2. Tell `Lego` where to get/set bytes into memory by defining and exporting `memory_ptr` function:\n\n```js\nlet memory = new ArrayBuffer(1024);\n\nexport function memory_ptr(): usize {\n    return changetype\u003cusize\u003e(memory);\n}\n\n// Help for set string into memory\nfunction saveStringIntoMemory(data: String): usize {\n    const len = raw.length;\n    let view = new DataView(memory);\n    for (let i=0;i\u003c(len as i32);i++) {\n        view.setUint8(i, raw.charCodeAt(i) as i8);\n    }\n    return len;\n}\n```\n\n3. Export `http_get` hook to `Lego`:\n\n```\nexport function http_get(inputLen: usize): usize {\n    return saveStringIntoMemory(helloWorld());\n}\n```\n\n4. Compiles into wasm and store in any path you like:\n\n```sh\n$ npm run build\n$ cp ./build/helloworld.wasm /path/to/wasm/helloworld.wasm\n```\n\n### Run `Lego`\n\n1. Setup environment varialble `LEGO_WASM_ROOT` as the root locatoin of your wasms.\n\n```\nexport LEGO_WASM_ROOT=\"/path/to/wasm\"\n```\n\n2. Here we go ~\n\n```\n$ /path/to/lego\n```\n\n### Request `Lego`\n\n```\n$ curl http://localhost:8000/helloworld | jq    # `helloworld` is the name of your wasm file without extension\n{\n  \"result\": \"hello world\"\n}\n```\n\nYou can find more AssemblyScript examples written in [assemblyscripts](./assemblyscripts/assembly).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshonenada%2Flego","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshonenada%2Flego","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshonenada%2Flego/lists"}