Simple API server
This tutorial will cover how to deploy a simple API on Deno Deploy.
Step 1: Write the API in a local file
// simple_api.js
import { serve } from "https://deno.land/std@0.201.0/http/server.ts";
serve((req: Request) => new Response("Hello World"));
This is a basic web server, and you can run it locally with:
deno run -A simple_api.js
This brings the server up on localhost:5000
.
To deploy this server on Deno Deploy, you can use the Github integration.
git init
git add .
Step 2: Create a new Github repo and push the local file to the Github repo
Create a new Github repo and record the git repo remote URL
From the local repo where
simple_api.js
resides, initialize git and push to the new remote repo:git init
git add simple_api.js
git commit -m "First commit"
git remote add <remote-url>
git push origin main
You now have a new Github repo with exactly one file in it.
Step 3: Deploy to Deno Deploy
- Navigate to https://dash.deno.com/ and click the New Project button.
- On the next page, choose the Deploy from Github repository card.
- To fill in the values on the form, choose:
- the new Github repo that you just created
- automatic (fastest)
main
branchsimple_api.js
as the entrypoint file
- the new Github repo that you just created
This downloads all dependencies of simple_api.js
, caches them, and gives you
an API at localhost:8000
that responds with "Hello World".