{"id":13694346,"url":"https://github.com/schollz/faas","last_synced_at":"2025-04-06T04:09:36.658Z","repository":{"id":57517299,"uuid":"198508442","full_name":"schollz/faas","owner":"schollz","description":"Make any Go function into a API (FaaS)","archived":false,"fork":false,"pushed_at":"2024-11-06T20:30:28.000Z","size":60,"stargazers_count":114,"open_issues_count":1,"forks_count":14,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-30T03:03:52.891Z","etag":null,"topics":["cloud","faas","faas-cli","faas-framework","faas-platform","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/schollz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2019-07-23T21:08:03.000Z","updated_at":"2025-03-08T21:02:49.000Z","dependencies_parsed_at":"2024-11-06T21:25:51.134Z","dependency_job_id":"ce1bd904-6d56-4acc-a7b7-30abef83b691","html_url":"https://github.com/schollz/faas","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schollz%2Ffaas","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schollz%2Ffaas/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schollz%2Ffaas/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schollz%2Ffaas/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/schollz","download_url":"https://codeload.github.com/schollz/faas/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247430869,"owners_count":20937874,"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":["cloud","faas","faas-cli","faas-framework","faas-platform","golang"],"created_at":"2024-08-02T17:01:29.909Z","updated_at":"2025-04-06T04:09:36.480Z","avatar_url":"https://github.com/schollz.png","language":"Go","readme":"# faas (funciton-as-a-service)\n\nMake any (Go) function into an API with one HTTP request.\n\nThis is a FaaS: *functions as a service*. But, in actuality, its more of a FaaSSS: *functions as a stupidly simple service*. Imagine [iron.io/functions](https://github.com/iron-io/functions), or [zeit/now](https://github.com/zeit/now-cli) or [openfaas](https://github.com/openfaas/faas) or [apex](https://github.com/apex/apex) or [sky-island](https://github.com/briandowns/sky-island) but more simple and more stupid.\n\nUnlike others, this FaaS requires **no coding**, **no init-ing**, **no pushing**, **no updating**, and **no bumping**. You Just make *one* HTTP request with the name of the package, the name of the function, and any input. Right now it only works for Go. It can easily be extended to Python (WIP).\n\nThe codebase is only about 600 lines of code in total. Basically a request tells the server to fetch the function, determine the inputs/outputs and write a wrapper function that is served from a Docker container.\n\n## Examples \n\nTry it right now with my instance at https://faas.schollz.com.\n\nYou can make (almost) any exported Go function into a API! \n\nRun [`Md5Sum`](https://github.com/schollz/utils/blob/adaa47085f7b6b1c3e1ecfebfb18028e08e0bde2/hash.go#L29-L34) to get a md5 hash of \"hello, world\":\n\n```bash\n$ curl https://faas.schollz.com/?import=github.com/schollz/utils\u0026func=Md5Sum(%22hello,%20world%22)\ne4d7f1b4ed2e42d15898f4b27b019da4\n```\n\nRun [`IngredientsFromURL`](https://github.com/schollz/ingredients/blob/23a2a0c2d9dc8988c33acf7650ae9284a59d0b20/ingredients.go#L153-L160) to get the ingredients from any website:\n\n```bash\n$ curl https://faas.schollz.com/?import=github.com/schollz/ingredients\u0026func=IngredientsFromURL(%22https://cooking.nytimes.com/recipes/12320-apple-pie%22)\n{\"ingredients\": [{\"name\":\"butter\",\"comment\":\"unsalted\",\"measure\":{\"amount\":2,\"name\":\"tablespoons\",\"cups\":0.25}},{\"name\":\"apples\",\"measure\":{\"amount\":2.5,\"name\":\"pounds\",\"cups\":14.901182654402104}},{\"name\":\"allspice\",\"comment\":\"ground\",\"measure\":{\"amount\":0.25,\"name\":\"teaspoon\",\"cups\":0.0104165}},{\"name\":\"cinnamon\",\"comment\":\"ground\",\"measure\":{\"amount\":0.5,\"name\":\"teaspoon\",\"cups\":0.020833}},{\"name\":\"salt\",\"comment\":\"kosher\",\"measure\":{\"amount\":0.25,\"name\":\"teaspoon\",\"cups\":0.0104165}},{\"name\":\"sugar\",\"comment\":\"plus 1 tablespoon\",\"measure\":{\"amount\":0.75,\"name\":\"cup\",\"cups\":1.5}},{\"name\":\"flour\",\"comment\":\"all purpose\",\"measure\":{\"amount\":2,\"name\":\"tablespoons\",\"cups\":0.25}},{\"name\":\"cornstarch\",\"measure\":{\"amount\":2,\"name\":\"teaspoons\",\"cups\":0.083332}},{\"name\":\"apple cider vinegar\",\"measure\":{\"amount\":1,\"name\":\"tablespoon\",\"cups\":0.125}},{\"name\":\"pie dough\",\"measure\":{\"amount\":1,\"name\":\"whole\",\"cups\":0}},{\"name\":\"egg\",\"measure\":{\"amount\":1,\"name\":\"whole\",\"cups\":0}}],\"err\": null\n```\n\nRun `MarkdownToHTML` from a [Go playground](https://play.golang.org/p/9xzE8Ivwupk):\n\n```bash\n$ curl -d '{\"markdown\":\"*hello*,**world**\"}' \\\n \t-H \"Content-Type: application/json\" -X POST \\\n \thttps://faas.schollz.com/?import=https://play.golang.org/p/9xzE8Ivwupk.go\u0026func=MarkdownToHTML\n\u003cp\u003e\u003cem\u003ehello\u003c/em\u003e,\u003cstrong\u003eworld\u003c/strong\u003e\u003c/p\u003e\n```\n\n## Usage \n\nYou can use `GET` or `POST` to submit jobs.\n\nFor the `GET` requests the syntax is\n\n```\n/?import=IMPORTPATH\u0026func=FUNCNAME(param1,param2...)\n```\n\nThe `IMPORTPATH` is the import path (e.g. github.com/x/y) or a URL containing the file with the function. The `FUNCNAME` is the name of the function. Note, you do need to URL encode the strings so that `FUNCNAME(\"hello, world\") -\u003e FUNCNAME(%22hello,%20world%22)`\n\n\nFor the `POST` requests the syntax is:\n\n```\n/?import=IMPORTPATH\u0026func=FUNCNAME\n```\n\nwith the body with the inputs `{\"param\":\"value\"}`.\n\nThat's it! The first time you run it will take ~1 minute while the Docker image is built.\n\n\n## How does it work?\n\nWhen you make a `POST`/`GET` request to the `faas` server it will locate the given function and given package and it will generate a Docker container that accepts a JSON input with the parameters and outputs a JSON containing the output variables. This Docker container automatically shuts down after some time of inactivity. Subsequent requests then will load the previously built container for use.\n\n## Host yourself\n\nYou need to [install Docker](https://docs.docker.com/install/linux/docker-ce/ubuntu/#install-docker-engine---community-1), and make sure `gzip` is installed.\n\nThen build `faas` with Go:\n\n```\ngit clone https://github.com/schollz/faas\ncd faas\ngo generate\ngo build -v\n```\n\nNow you can run:\n\n```\n./faas --debug\n```\n\nNow you can try it out:\n\n```\ncurl http://localhost:8090/?import=github.com/schollz/utils\u0026func=Md5Sum(%22hello,%20world%22)\n```\n\nOR post data:\n\n```\ncurl -d '{\"s\":\"hello, world\"}' -H \"Content-Type: application/json\" -X POST http://localhost:8090/?import=github.com/schollz/utils\u0026func=Md5Sum\n```\n\nNote that the JSON `\"s\"` comes from the function `Md5Sum` itself.\n\n## License\n\nMIT\n","funding_links":[],"categories":["开源类库","Open source library"],"sub_categories":["Serverless"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschollz%2Ffaas","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fschollz%2Ffaas","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschollz%2Ffaas/lists"}