Giter Site home page Giter Site logo

demo-deno-restful-api-example's Introduction

deno restful api

一个基于 deno + drash + mongodb 的Restful API示例,本项目仅用于自学deno,不定期更新。。。

技术栈

  • Deno:Deno是适用于 JavaScriptTypeScript 的简单,现代且安全的运行时,它使用V8并内置于Rust。

  • Deno-Drash:基于 DenoREST 风格 HTTP 服务器 零依赖 微框架。

  • MongoDB:NoSQL,基于文档的通用分布式数据库。

使用环境

运行前请确认已安装Deno:

Shell (Mac, Linux):

curl -fsSL https://deno.land/x/install/install.sh | sh

PowerShell (Windows):

iwr https://deno.land/x/install/install.ps1 -useb | iex

Homebrew (Mac):

brew install deno

PS:使用vscode的话推荐使用Deno官方插件。

运行方法

  1. config.example.ts 文件更名为 config.ts, 并修改mongodb地址为你的数据库地址,mongodb官方提供免费的数据库服务,移步mongodb官网自行注册
# config.ts
-  MONGODB_URL: "your mongodb url",
+  MONGODB_URL: ”mongodb+srv://<yourname>:<yourpassword>@dev.syfk0.mongodb.net“ # mongodb官方库提供的地址类似这样,注意不包含”<>“字符
  1. 启动
# deno 在运行时需要指定读写等权限,官方宣传这样更安全(emmm。。。)
deno run --allow-net --allow-write --allow-read --allow-plugin --unstable app.ts
  1. 浏览器打开 http://localhost:3000 .

API

  • http://localhost:3000/user
    • 获取用户列表功能
    • 用户注册功能
    • 用户删除功能
    • [] 用户密码加密处理
    • [] 登录功能
# GET
curl -X GET http://localhost:3000/user
# POST
curl -X POST -d "username=<替换为名字>&userpassword=<替换为密码>" http://localhost:3000/user
# DELETE
curl -X DELETE -d "userId=<替换为用户ID>" http://localhost:3000/user

demo-deno-restful-api-example's People

Contributors

intvergil avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.