zhaoyingzi

api接口暴露

测试接口是否正常,我们可以使用测试工具:postman insomnia

BE: BackEnd 后端

  • express中一个路由即一个接口,二级路由写在routes文件夹里面对应的.js文件里

  • api接口暴露的方式有两种:

    • 第一种: 使用模板进行暴露,但是要将数据做字符串转换,然后使用ejs的非转义输出
      router.get(\'/\',function( req,res,next ) {
        res.render(\'mine\', {
          mine: JSON.stringify({
            ret: true,
            username: \'yyb\',
            password: 123
          })
        })
      })
    
    • 第二种: 使用json()
      router.get(\'/\',function( req,res,next ) {
        res.json({
          ret: true,
           username: \'yyb\',
           password: 123
         })
      })

分类:

技术点:

相关文章:

  • 2021-12-10
  • 2021-08-16
  • 2021-07-07
  • 2021-11-16
  • 2021-09-19
  • 2022-12-23
  • 2021-10-19
  • 2022-01-22
猜你喜欢
  • 2021-11-09
  • 2021-06-16
  • 2022-12-23
  • 2021-10-18
  • 2021-12-16
  • 2022-12-23
相关资源
相似解决方案