TypeScript编写Express的Get、Post请求

        使用TS编写Express的Get、Post请求,具体步骤不细述

        首先安装Express:

npm install express

        代码中导入Express,获取router:

import express = require('express');
var router = express.Router();

        一、Get请求:

        Get请求使用参数,使用方法req.query.name来获取具体参数,name是参数名

router.get('/test',function(req,res){
  
  res.send(req.query.name);
});

        使用postman测试结果:

        二、Post请求:

        Post请求使用参数,使用方法req.body.name来获取具体参数,name是参数名

router.post('/test1',function(req,res){
  
  res.send(req.body.name);
});

        使用postman测试结果:

扫描二维码关注公众号,回复: 13039254 查看本文章

猜你喜欢

转载自blog.csdn.net/qq_41061437/article/details/112908807