Skip to content

NickolasBenakis/JurassicPark

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JurassicPark

Deno is a simple, modern and secure runtime for JavaScript and TypeScript that uses V8 and is built in Rust.

This is a simple Rest API build with oak framework and Deno.

Learn more about Deno and oak

Server

import { Application } from "https://deno.land/x/oak/mod.ts";
import router from "./src/routes/routes.ts";

const port = 8000;
const app = new Application();

app.use(router.routes());
app.use(router.allowedMethods());

console.log(`Server running on port ${port}`);
await app.listen({ port });

Routes

import { Router } from "https://deno.land/x/oak/mod.ts";
import {
  getDinosaur,
  getDinosaurs,
  addDinosaur,
  updateDinosaur,
  deleteDinosaur,
} from "../controllers/dinosaurs.ts";

const router = new Router();

router.get("/api/v1/dinosaurs", getDinosaurs)
  .get("/api/v1/dinosaurs/:id", getDinosaur)
  .post("/api/v1/dinosaurs", addDinosaur)
  .put("/api/v1/dinosaurs/:id", updateDinosaur)
  .delete("/api/v1/dinosaurs/:id", deleteDinosaur);

export default router;

Types

export interface Dinosaur {
  id: string;
  name: string;
  era: string;
  area: string;
  diet: string;
}

Endpoints examples

  • /api/v1/dinosaurs
   {
    "success": true,
    "data": [
      {
        "id": "1",
        "name": "Achillobator",
        "era": "Late Cretaceous",
        "area": "Mongolia",
        "diet": "carnivorous"
      },
      {
        "id": "2",
        "name": "Agilisaurus",
        "era": "Late Jurassic",
        "area": "China",
        "diet": "herbivorous"
      },
      {
        "id": "3",
        "name": "Melanorosaurus",
        "era": "Late Triassic",
        "area": "South Africa",
        "diet": "omnivorous"
      }
    ]
  }
  • /api/v1/dinosaurs/1
  {
    "success": true,
    "data": [
      {
        "id": "1",
        "name": "Achillobator",
        "era": "Late Cretaceous",
        "area": "Mongolia",
        "diet": "carnivorous"
      }
    ]
  }

About

simple deno rest api with oak framework 🦕

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published