I found AWS lambda in July 2015 and became a big fan of Function as a Service (FaaS) since then, Three years ago I built my own FaaS framework fx at a Go Hackathon, then I published it on Hacker News, it quickly became one of Github trending repositories and pull in 700+ stars in one day.
While I was a little bloated, I struggled to find real-world scenario for it. This week I decided to become my own user of it, so I built an Web App with fx, and fx is amazingly handy in building APIs with FaaS way.
Hello World
fx is a simple tool I build to simplify the API development, let's take a look at how easy we build an API with fx.
I found AWS lambda in July 2015 and became a big fan of Function as a Service (FaaS) since then, Three years ago I built my own FaaS framework fx at a Go Hackathon, then I published it on Hacker News, it quickly became one of Github trending repositories and pull in 700+ stars in one day.
While I was a little bloated, I struggled to find real-world scenario for it. This week I decided to become my own user of it, so I built an Web App with fx, and fx is amazingly handy in building APIs with FaaS way.
Hello World
fx is a simple tool I build to simplify the API development, let's take a look at how easy we build an API with fx.
You define an API in
func.js
, looks like this.Then you can deploy your function to be a service with fx with one command.
Let's test it with
curl
.fx in fleself.com
fleself.com is a website (UI and APIs) are totally written with JavaScript/Node, all the APIs are built with fx.
Architecture
This's overall APIs code structure of fleself.com,
And each source code of an API is just a function, take
/api/tweets/delete
as example,GitHub Actions Workflows
The whole development process is managed on GitHub, and I use GitHub Actions to do CI/CD, its GitHub Actions workflow looks like this.
Caddy as Services Proxy
And I use Caddy as the frontend of the service, the config looks like this,