We will create an API that takes a unixtime and returns the time.
# Set the target
rustup target add wasm32-unknown-unknown
# A browser will open, so click on "Allow"
yarn global add wrangler
wrangler login
Follow the Official Guide to generate a project from the template.
npx wrangler generate unix_time_formatter https://github.com/cloudflare/workers-sdk/templates/experimental/worker-rust
cd unix_time_formatter
wrangler dev
When a request is received, it returns "Hello, World!".template
❯ curl localhost:8787
Hello, World!
We will use Chrono to return the unixtime in the format yyyy/mm/dd (day of the week) HH:MM:SS. Modified Code
(If you save while running wrangler dev, hot reloading will run and it will be updated automatically.)
curl -X GET http://127.0.0.1:8787/$(date +%s)
2023/7/21(Fri) 08:51:05
wrangler publish
# Published worker-rust (0.29 sec)
# URL will be generated
After running wrangler publish, a URL will be issued.
curl -X GET [Insert the issued URL here]/$(date +%s)
2023/7/21(Fri) 08:52:33