diff --git a/README.md b/README.md index acf66be..7a45ce2 100644 --- a/README.md +++ b/README.md @@ -9,15 +9,26 @@ Stupid simple FaaS (Function as a Service) runner using GitHub Gists. - Code is executed in a Node.js Worker Thread Pool (tinypool). - Pretty errors. -## Todo - -- [ ] Consider adding support for other languages and runtimes. -- [ ] Consider allowing importing http modules (--experimental-network-imports) or Deno. -- [ ] Consider adding a simple, Monaco editor-based web interface. -- [ ] Consider adding GitHub repo support. -- [ ] Consider sandboxing the code execution. -- [ ] Add /gist/:gistId route to list all the runnable files in the Gist. -- [ ] Add more tests. +## Function syntax + +Service functions can be written in JavaScript or TypeScript. The function should be the default export of the file. For JavaScript, the function can be either CommonJS or ES module (ESM is preferred, for CJS use `.cjs` extension). + +```ts +/** + * @param {Object} context - The context object. + * @param {Object} context.req - The request object. + * { + * headers: { [key: string]: string }, + * method: string, + * url: string, + * body: string + * } + * @returns {Promise} The result of the function. + */ +export default async ({ req }) => { + return 10 % 5; +}; +``` ## API Docs @@ -35,3 +46,13 @@ Run the code in the specified file in the Gist. #### Response Whatever the code in the file returns. If it's a valid JSON, it's gonna be parsed and returned as JSON. If not it's gonna be served as HTML. + +## Todo + +- [ ] Consider adding support for other languages and runtimes. +- [ ] Consider allowing importing http modules (--experimental-network-imports) or Deno. +- [ ] Consider adding a simple, Monaco editor-based web interface. +- [ ] Consider adding GitHub repo support. +- [ ] Consider sandboxing the code execution. +- [ ] Add /gist/:gistId route to list all the runnable files in the Gist. +- [ ] Add more tests.