Skip to content

Route

自 1.4.0 起

HTTP 路由定义。

签名

typescript
interface Route<Path extends string, Method extends HTTPMethod, Handler, Context = object> {
  path: Path
  method: Method
  handler: Handler
}

参数

参数描述
Path路由路径字符串
MethodHTTP 方法
Handler路由处理函数类型
Context请求上下文类型

描述

定义包含路径、方法和处理函数的 HTTP 路由。

示例

基本用法

typescript
import type { Route, HTTPMethod } from 'uni-types'

type GetUser = Route<'/users/:id', 'GET', (ctx: { params: { id: string } }) => Promise<Response>>

相关

基于 MIT 许可发布