Bootstrap a Compute project with Fastly Fiddle
The Fastly CLI now supports bootstrapping Compute projects using fiddles made in Fastly Fiddle as a template. Whether you want to start coding in Fiddle and then bring your project local, or make use of one of the hundreds of code examples on our Developer Hub, `fastly compute init` just got a lot more powerful.
Starting a new Compute project using the Fastly CLI is very quick and straightforward, but sometimes you don't want to set up a local development environment when trialling new ideas or demonstrating a proof-of-concept.
This is where Fastly Fiddle comes in handy. It enables you to easily share and iterate on your VCL or Compute code, while allowing others to clone and contribute — all without needing to install anything.
Many of the sample solutions in our code example library already use Fiddle to allow you to run the example code right there in the documentation. This pattern is pretty popular across the web, with services like Glitch and Runkit pioneering the ability to write code in pre-configured runtime environments with little or no setup, reducing the distance between idea and execution.
So what happens when you've used one of these tools or found a code example, so you know you have a solution that works the way you want, and now it's time to make it real? You might now be more motivated to install local tooling and set up an environment, but it'd be really great if you could convert your experiment into a real project in an automated way.
Introducing the INSTALL tab
Code examples in our Developer Hub now have a new INSTALL tab. First select the language implementation you require (e.g. JavaScript), then click the “INSTALL” link that appears above the displayed code to see the options for how to adopt that code:
You’ll notice there are two options for installing the code example: one that creates a local development environment, and one that deploys the code directly to a live Compute service using our new “Cloud Deploy” feature.
Start a local project from a code example
Start by opening up a terminal shell and create a new directory, then run the following command (as it is documented in Step 3 in the solution page):
$ fastly compute init --from=https://fiddle.fastlydemo.net/fiddle/f077af30
Follow the prompts, and you'll end up with something like this::
Creating a new Compute project (using --from to locate package template).✓ Initializing...✓ Fetching package template...