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
5 Answers
Reset to default 7Awesome 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
版权声明:本文标题:javascript - Creating Rest API in Deno - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742132554a2422228.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论