Need help with cloudflare-2020-general-engineering-assignment?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

139 Stars 392 Forks MIT License 7 Commits 74 Opened issues

Services available


Need anything else?

Contributors list

No Data

General Assignment

What is it?

In this exercise, you'll deploy a Cloudflare Workers project in order to build a linktree-style website. Below is a list of requirements and success criteria for your finished project.


Deploy a JSON API

Create a new Workers project using Wrangler. This project will respond to two kinds of requests, one to generate a JSON API (defined below), and second, to serve an HTML page (see "Set up an HTML page")

To begin, you should define an array of links. The links should be a JavaScript array, with a number of link objects, each with a name and URL string. See the below example for one of these link objects:

{ "name": "Link Name", "url": "https://linkurl" }

You should define at least three link objects inside of your array.

Once you've defined this array, set up a request handler to respond to the path

, and return the array itself as the root of your JSON response.

In addition, you should ensure that the API response has the correct

header to indicate to clients that it is a JSON response.

You should be able to test that this works as expect by running

wrangler dev
to access your Workers application locally. Visit
to confirm that your application returns the link array as a JSON response.

Set up an HTML page

With your API deployed, you can flesh out the rest of your application. If the path requested is not

, your application should render a static HTML page, by doing the following steps:
  1. Retrieve a static HTML page
  2. Get the links from your previously deployed JSON response
  3. Use HTMLRewriter to add these links to the static HTML page
  4. Return the transformed HTML page from the Worker

Retrieve a static HTML page

Your Worker should begin by making a

request to

The response from this URL will be a static HTML page that you can enhance using HTMLRewriter.

Note that you need to make the request to this HTML page in your Worker. The URL will return multiple static HTML pages randomly, so you should not copy-paste the HTML into your Worker, as you will not complete the exercise correctly.

Use HTMLRewriter to update the page

Using HTMLRewriter, you should transform the static HTML response from $URL, and pass in the links array you previously defined into the page. Note that this means that your links array should be available as a variable for both your previous

endpoint, as well as this static HTML section. Target the
selector, and add in a new
for each link in your API using HTMLRewriter.

In order to use the links inside of your HTMLRewriter handler, you can use a custom class to pass in arguments, for instance:

class LinksTransformer {
  constructor(links) {
    this.links = links

async element(element) { // Your code } }

Here's what the output of the

section should look like:

You should also remove the

display: none
from the
container, and inside of it, update the two child elements to show your user avatar and name.

To do this, target

and set the
attribute to a profile image.

Do the same for

, setting the text to your username.

Return the transformed HTML page from the Worker

Once you've passed the static HTML response through your HTMLRewriter instance, you can return it as the response from the Worker.

Ensure that the correct

header is set for this page, allowing it to render as HTML in a browser.

Once you've completed the code for this project, you can deploy it using

wrangler publish
. Follow our Quick Start guide to learn how to deploy Workers applications. You should submit both the JSON API URL and your deployed webpage for grading.

Add a link to your deployed worker to your repo

Create a URL.txt that contains one line in it with the URL of your page. For example if my assignment was deployed at I would put the following in URL.txt:

We will test your code by visiting the URL in that file and the /links endpoint as well. In the above example we would test and .

Extra Credit

  1. Provide social links

Remove the

display: none
style from
, and add any number of social links as children to the container. The children of this container should be
links, with
icons as the children of those links. For example SVGs, use

  1. Update the title field

Using the HTMLRewriter, target the

tag and update the text inside to your name.
  1. Change the background color:

Using HTMLRewriter, target the

element and change the background color. You can simply swap out the
class with another class from Tailwind CSS's color palette, or set a
style to a color, gradient, or image of your choice.
  1. Do the Systems Assignment that depends on the work you've done here.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.