Basic Rest API with Deno

Deno REST API

Allow to test Deno with basic Rest API

Created and maintained by veben

I. Requirements

1. MongoDb configuration

Create a .env file with following content:

DB_NAME=<database name>
DB_HOST_URL=<connection string>

2. Deno installation

  1. Install Deno
curl -fsSL https://deno.land/x/install/install.sh | sh
  1. Add following lines to ~.zshrc file
# For Deno
export DENO_INSTALL="/home/veben/.deno"
export PATH="$DENO_INSTALL/bin:$PATH"

  1. Check version
deno -V

II. Launch server

deno run --allow-write --allow-read --allow-plugin --allow-net --allow-env --unstable ./main.ts
n

III. Test API

1. Create a dinosaur

curl -X POST --header "Content-Type: application/json" --data '{
  "name": "stegosaurus",
  "weight": 6000,
  "kingdom": "animalia",
  "phylum": "chordata",
  "clade": "dinosauria"
}' "http://localhost:5000/api/dinosaur"

2. Get all dinosaurs

curl -X GET "http://localhost:5000/api/dinosaur"

Download Details:

Author: veben

Source Code: https://github.com/veben/deno_rest_api

#deno #nodejs #node #javascript

Basic Rest API with Deno
2.95 GEEK