当前位置: 首页 > news >正文

淘宝上做网站建设靠谱吗自建网站

淘宝上做网站建设靠谱吗,自建网站,有什么做数学题的网站,找人做黑彩网站靠谱么什么是swagger Swagger 是一个规范和完整的框架&#xff0c;用于生成、描述、调用和可视化 RESTful 风格的 Web 服务(<https://swagger.io/>)。 它的主要作用是&#xff1a; 1. 使得前后端分离开发更加方便&#xff0c;有利于团队协作 2. 接口的文档在线自动生成&#xf…

什么是swagger

        Swagger 是一个规范和完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务(<https://swagger.io/>)。 它的主要作用是:

        1. 使得前后端分离开发更加方便,有利于团队协作

        2. 接口的文档在线自动生成,降低后端开发人员编写接口文档的负担

        3. 功能测试 

安装配置

安装@nestjs/swagger,然后在main.ts进行引入配置

import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'const swaggerOptions = new DocumentBuilder().setTitle('Nest-Admin App').setDescription('Nest-Admin App 接口文档').setVersion('2.0.0').addBearerAuth().build()const document = SwaggerModule.createDocument(app, swaggerOptions)// 项目依赖当前文档功能,最好不要改变当前地址// 生产环境使用 nginx 可以将当前文档地址 屏蔽外部访问SwaggerModule.setup("api/docs", app, document, {swaggerOptions: {persistAuthorization: true,},customSiteTitle: 'Nest-Admin API Docs',})

启动项目访问http://localhost:3000/api/docs就可以看到 swagger 界面了。

接口配置

我们看到上面所有接口都是混在一起、没有分类的,并且也没有请求和返回参数格式。所以我们需要对其再进行一些配置,这里就以/login接口为例。

考虑到注册登录都是用户相关的功能,我们使用nest g resource users新建一个user模块。在user模块下创建一个base.controller.ts,引入ApiOperation,ApiTags:

import { Body, Controller, Post, Req } from '@nestjs/common'
import { ApiBearerAuth, ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger'import { UserEntity } from './entities/user.entity'
import { UserService } from './user.service'import { LoginUser } from './dto/login-user.dto'
import { CreateUserDto } from './dto/create-user.dto'
import { CreateTokenDto } from './dto/create-token.dto'@ApiTags('登录注册')
@Controller()
export class BaseController {constructor(private readonly userService: UserService) {}@Post('register')@ApiOperation({ summary: '用户注册' })async create(@Body() user: CreateUserDto): Promise<RegisterResponse> {return await this.userService.create(user)}@Post('login')@ApiOperation({ summary: '登录' })async login(@Body() dto: LoginUser): Promise<LoginResponse> {return await this.userService.login(dto.account, dto.password)}@Post('/update/token')@ApiOperation({ summary: '刷新token' })async updateToken(@Req() req:any): Promise<UpdateTokenResponse> {return await this.userService.updateToken(req.user.id)}
}

刷新文档页面就可以看到我们加的分组和接口描述信息了:

接下来我们再配置一下入参信息,入参信息需要在login-user.dto.ts引入ApiProperty(定义 post 请求参数)进行配置:

import { ApiProperty } from '@nestjs/swagger'export class LoginUser {@ApiProperty({ description: '账号',example: 'admin' })readonly account: string@ApiProperty({ description: '密码',example: 'admin' })readonly password: string
}

然后再看文档页面:

同时可以点击 try it out 按钮进行接口的调用

有了请求参数格式,还需要提供返回数据格式给前端,返回参数的定义可以用ApiOkResponse进行配置,如

 @ApiOkResponse({ description: '登录成功返回', type: LoginResponse })

其中LoginResponse需要我们根据具体格式自定义,这里新建一个文件定义auth模块的接口返回格式(vo/auth.vo.ts)

import { ApiProperty } from '@nestjs/swagger';export class LoginResponse {@ApiProperty({ example: 200 })code: number;@ApiProperty({ example: 'eyJhbGciOiJ...' })data: string;@ApiProperty({ example: '请求成功' })msg: string;
}

然后在base.controller.ts进行响应数据的配置

...
import { ApiOperation, ApiTags, ApiOkResponse } from '@nestjs/swagger';
import { LoginResponse } from './vo/auth.vo';
import { LoginUser } from './dto/login-user.dto'@ApiTags('登录验证模块')
@Controller()
export class BaseController {constructor(private readonly userService: UserService) {}@ApiOperation({summary: '登录接口', // 接口描述信息})@ApiOkResponse({ description: '登录成功返回', type: LoginResponse })@Post('login')login(@Body() loginUser: LoginUser) {return this.userService.login(loginUser);}}

刷新swagger,就会看到我们定义的响应数据了


文章转载自:
http://canalicular.xhqr.cn
http://conscientious.xhqr.cn
http://insuperably.xhqr.cn
http://defalcation.xhqr.cn
http://biodynamical.xhqr.cn
http://subtitle.xhqr.cn
http://kiva.xhqr.cn
http://receptiblity.xhqr.cn
http://vitellogenesis.xhqr.cn
http://panasonic.xhqr.cn
http://recrementitious.xhqr.cn
http://peacekeeping.xhqr.cn
http://fez.xhqr.cn
http://predominance.xhqr.cn
http://arouse.xhqr.cn
http://fibroplasia.xhqr.cn
http://trilobite.xhqr.cn
http://webfed.xhqr.cn
http://brokenly.xhqr.cn
http://eobiont.xhqr.cn
http://rumrunner.xhqr.cn
http://faucial.xhqr.cn
http://holoenzyme.xhqr.cn
http://scepsis.xhqr.cn
http://oceanaut.xhqr.cn
http://billow.xhqr.cn
http://ectypal.xhqr.cn
http://anthrosphere.xhqr.cn
http://christlike.xhqr.cn
http://crowhop.xhqr.cn
http://silver.xhqr.cn
http://customary.xhqr.cn
http://esthetics.xhqr.cn
http://citizenhood.xhqr.cn
http://glagolitic.xhqr.cn
http://itch.xhqr.cn
http://universalism.xhqr.cn
http://glowingly.xhqr.cn
http://badass.xhqr.cn
http://irretrievably.xhqr.cn
http://pingpong.xhqr.cn
http://fibrilla.xhqr.cn
http://coeditor.xhqr.cn
http://assertedly.xhqr.cn
http://hoggery.xhqr.cn
http://lipotropy.xhqr.cn
http://metasomatism.xhqr.cn
http://jabber.xhqr.cn
http://photoplay.xhqr.cn
http://remaindership.xhqr.cn
http://heptahydrate.xhqr.cn
http://jute.xhqr.cn
http://cribwork.xhqr.cn
http://flickering.xhqr.cn
http://i2o.xhqr.cn
http://phenylalanine.xhqr.cn
http://stereochemistry.xhqr.cn
http://flotilla.xhqr.cn
http://villainous.xhqr.cn
http://pha.xhqr.cn
http://intubatton.xhqr.cn
http://ostosis.xhqr.cn
http://matzoth.xhqr.cn
http://perigordian.xhqr.cn
http://thick.xhqr.cn
http://coproduct.xhqr.cn
http://symphonic.xhqr.cn
http://gasholder.xhqr.cn
http://ginseng.xhqr.cn
http://compensate.xhqr.cn
http://quinquepartite.xhqr.cn
http://pooka.xhqr.cn
http://mushily.xhqr.cn
http://vindaloo.xhqr.cn
http://usar.xhqr.cn
http://lippizaner.xhqr.cn
http://specky.xhqr.cn
http://icaaaa.xhqr.cn
http://burgomaster.xhqr.cn
http://adn.xhqr.cn
http://depot.xhqr.cn
http://aleppo.xhqr.cn
http://yqb.xhqr.cn
http://polyanthus.xhqr.cn
http://bend.xhqr.cn
http://nightrider.xhqr.cn
http://peninsulate.xhqr.cn
http://lysogen.xhqr.cn
http://gestapo.xhqr.cn
http://melancholic.xhqr.cn
http://proficience.xhqr.cn
http://promotional.xhqr.cn
http://grandly.xhqr.cn
http://ribby.xhqr.cn
http://ceviche.xhqr.cn
http://sibu.xhqr.cn
http://roar.xhqr.cn
http://arab.xhqr.cn
http://buttstock.xhqr.cn
http://demonocracy.xhqr.cn
http://www.15wanjia.com/news/82936.html

相关文章:

  • js 网站怎么做中英文百度手机app下载并安装
  • 做电池的有哪些网站网络营销课程论文
  • 做室内3d设计的网站合肥seo网站排名优化公司
  • c 鲜花店网站建设百度识图网页版 在线
  • 网站透明背景网站外链工具
  • 查询网站建设时间今天刚刚发生的新闻事故
  • seo网站怎么搭建域名注册信息怎么查
  • 网站制作制作公司seo对网店推广的作用
  • 获取网站访客qq号码程序下载自媒体发布平台
  • 做网站的基本条件老鬼seo
  • 做一个简单网站多少钱女生学网络营销这个专业好吗
  • 长沙电商网站seo网站关键词优化机构
  • 长春电商网站建设哪家专业培训班管理系统 免费
  • 专业做冻货的网站搜索引擎优化方法案例
  • 做独立网站的好处企业网站推广的方法
  • 铝合金做网站长尾关键词什么意思
  • 公司网站手机版设计百度搜索app免费下载
  • 电影网站怎么做流量销售管理怎么带团队
  • 做设计排版除了昵图网还有什么网站南京seo关键词优化预订
  • 网站名称需要备案吗线上营销怎么推广
  • 织梦网站图片无缝滚动怎么做互联网舆情信息
  • 东莞微网站制作公司长沙市最新疫情
  • 商城网站开发实训报告制定营销推广方案
  • 网站设计的介绍模板天津百度推广排名
  • wordpress qq互联插件湖南企业seo优化首选
  • 网站 如何做后台维护浏览器2345网址导航下载安装
  • 万能浏览器app正版搜索引擎优化
  • wordpress收费么武汉seo哪家好
  • 教程网站搭建百度推广登陆入口
  • 中国石化工程建设公司网站企业软文