admin管理员组

文章数量:1323342

I am working on creating REST API in Deno but could not get a handful resources. Could someone help me to get started with? Something similar to express router :

router.get('/', function (req, res) {

});

router.post('/savedata', function (req, res) {

});

I am working on creating REST API in Deno but could not get a handful resources. Could someone help me to get started with? Something similar to express router :

router.get('/', function (req, res) {

});

router.post('/savedata', function (req, res) {

});
Share Improve this question edited May 17, 2020 at 5:05 Yangshun Tay 53.2k33 gold badges123 silver badges150 bronze badges asked Aug 14, 2019 at 6:27 Sandeep PatelSandeep Patel 5,1483 gold badges23 silver badges40 bronze badges 1
  • Try this: dev.to/kryz/write-a-small-api-using-deno-1cl0 using oak middleware – Kushal Bhalaik Commented Feb 20, 2020 at 6:40
Add a ment  | 

5 Answers 5

Reset to default 7

Awesome Deno is a list of existing tools built to work on Deno, and the list is actively maintained by Deno contributors. You might be able to find useful frameworks there.

Oak and ABC are two I know from the list that are actively maintained. You might also find other frameworks that fits your need better.

Oak Framework is used mainly for API purposes. You can follow this awesome step-by-step guide to develop a simple REST API in deno using Deno, Typescript and Oak.

https://codehexz./blog/getting-started-with-deno/

If you intend using the OAK Framework, this could be an approach.

import { Router } from "https://deno.land/x/oak/mod.ts";

    const router = new Router();

    router.get('/', function ({ response }) {

    });

    router.post('/savedata', async function ({ request, response }) {

    });

Note that there is a detail above: The functions receive a context object as standard parameter (e.g. router.get('/', function (context) { ... }) so an alternative could be using the destructuring assignment (e.g.router.get('/', ({ request, response, next})).

Source: OAK Documentation

I personally liked the annotation based Alosaur framework having annotations like @Controller which also supports dependency injection.

https://github./shantanum91/DenoRentApp

I have created a boilerplate based on Oak. It could be helpful for those who are beginning with deno:

Deno REST: https://github./vicky-gonsalves/deno_rest

本文标签: javascriptCreating Rest API in DenoStack Overflow