Forest Forest
💒 首页
  • v1.5.30
  • v1.5.28
  • 🎄 ForestX
🌰 案例
💖 支持
🛫 更新记录
🧢 开发团队
⚒️ 参与贡献
  • MaxKey - 业界领先的身份管理和认证产品 (opens new window)
  • Snowy - 国内首个国密前后端分离快速开发平台 (opens new window)
  • Eoapi - 一个开源、可拓展的 API 工具平台 (opens new window)
  • Gitee (opens new window)
  • Github (opens new window)
💒 首页
  • v1.5.30
  • v1.5.28
  • 🎄 ForestX
🌰 案例
💖 支持
🛫 更新记录
🧢 开发团队
⚒️ 参与贡献
  • MaxKey - 业界领先的身份管理和认证产品 (opens new window)
  • Snowy - 国内首个国密前后端分离快速开发平台 (opens new window)
  • Eoapi - 一个开源、可拓展的 API 工具平台 (opens new window)
  • Gitee (opens new window)
  • Github (opens new window)
  • 序言

    • 🎁 新手介绍
    • 📖 文档
    • 🌰 使用案例
    • 🕵️‍ 关于作者
    • 👨‍🎓 贡献者列表
  • 入门

    • 🎬 安装配置说明
    • 🏹 Springboot环境安装
    • 📐 Springboot环境配置
    • 🎯 Springboot环境使用
    • 🏹 Spring环境安装
    • 📐 Spring环境配置
    • 🎯 Spring环境使用
    • 🏹 原生Java环境安装
    • 📐 原生Java环境配置
    • 🎯 原生Java环境使用
    • 🧬 编程式接口
  • 配置项

    • 👜 Springboot环境配置项
    • 👝 Spring环境配置项
    • 🎒 原生Java环境配置项
    • 📚 配置优先级/作用域
  • 声明式接口

    • 🧱 构建接口
    • 🍀 请求方法
      • GET 请求
      • POST 请求
      • PUT 请求
      • HEAD 请求
      • DELETE 请求
      • OPTIONS 请求
      • OPTIONS 请求
      • TRACE 请求
      • PATCH 请求
      • 动态 HTTP 请求方法
    • 🚚 请求地址
    • 🎈 URL 参数
    • 🍭 请求头
    • 👔 请求体
    • 🍮 后端框架
    • 🧁 接口注解
    • 📬 接收数据
    • 🍛 数据转换
    • 🍓 成功/失败条件
    • 🍌 重试机制
    • 🥂 重定向
    • 🍔 Gzip解压
    • 🎂 日志管理
    • ⚽ 回调函数
    • 🍟 异步请求
    • 🛡️ HTTPS
    • 🍪 使用Cookie
    • 🛸 使用代理
    • 🍉 上传下载
    • 🚑 异常处理
  • 编程式接口

    • 请求API

      • 🚀 请求对象
      • 🚢 请求属性
      • ✨ 执行请求
      • 🎊 后端框架
      • 🎪 请求类型
      • 🔮 请求地址
      • 🧀 URL 参数
      • 🚅 请求头
      • 🚋 请求体
      • ⚓ 回调函数
      • 🚁 异步请求
      • 🥯 Cookie
      • 🍜 成功/失败条件
      • 🌶️ 重试机制
      • ⛵ 重定向
      • 🛰️ 请求代理
    • 响应API

      • 🌠 响应对象
      • ✒️ 读取数据
      • 🦋 响应状态码
      • 🏥 响应错误处理
      • 🎧 响应头
      • 🥞 Cookie
  • 模板表达式

    • 🍬 Hello World
    • 🍹 配置属性引用
    • 🍖 变量引用
    • 🥃 动态变量绑定
    • 🥗 参数序号引用
    • 🍍 引用对象属性
    • 🥝 调用对象方法
  • 高级特性

    • 🥪 拦截器
    • 🍏 自定义注解
    • 🍇 组合注解
    • 🥑 自定义转换器
  • v1.5.28文档
  • 声明式接口
公子骏
2022-07-01
目录

🍀 请求方法

Forest 使用不同的请求注解来标识某个接口方法来进行发送不同类型的请求,其支持的HTTP方法如下表所示:

HTTP 请求方法 请求注解 描述
GET @Get、@GetRequest 获取资源
POST @Post、@PostRequest 传输实体文本
PUT @Put、@PutRequest 上传资源
HEAD @HeadRequest 获取报文首部
DELETE @Delete、@DeleteRequest 删除资源
OPTIONS @Options、@OptionsRequest 询问支持的方法
TRACE @Trace、@TraceRequest 追踪路径
PATCH @Patch、@PatchRequest 更新资源的某一部分
不定方法 @Request 可动态传入HTTP方法

# GET 请求

使用@Get注解或@GetRequest注解

@Get("http://localhost:8080/hello")
String simpleGet1();

@GetRequest("http://localhost:8080/hello")
String simpleGet2();
1
2
3
4
5

# POST 请求

使用@Post注解或@PostRequest注解

@Post("http://localhost:8080/hello")
String simplePost1();

@PostRequest("http://localhost:8080/hello")
String simplePost2();
1
2
3
4
5

# PUT 请求

使用@Put注解或@PutRequest注解

@Put("http://localhost:8080/hello")
String simplePut1();

@PutRequest("http://localhost:8080/hello")
String simplePut2();
1
2
3
4
5

# HEAD 请求

使用@HeadRequest注解

为了避免于@Header注解产生歧义和混淆,Forest 没有提供@Head注解

@HeadRequest("http://localhost:8080/hello")
String simpleHead();
1
2

# DELETE 请求

使用@Delete注解或@DeleteRequest注解

@Delete("http://localhost:8080/hello")
String simpleDelete1();

@DeleteRequest("http://localhost:8080/hello")
String simpleDelete2();
1
2
3
4
5

# OPTIONS 请求

使用@Options注解或@OptionsRequest注解

@Options("http://localhost:8080/hello")
String simpleOptions1();

@OptionsRequest("http://localhost:8080/hello")
String simpleOptions2();
1
2
3
4
5

# OPTIONS 请求

使用@Options注解或@OptionsRequest注解

@Options("http://localhost:8080/hello")
String simpleOptions1();

@OptionsRequest("http://localhost:8080/hello")
String simpleOptions2();
1
2
3
4
5

# TRACE 请求

使用@Trace注解或@TraceRequest注解

@Trace("http://localhost:8080/hello")
String simpleTrace1();

@TraceRequest("http://localhost:8080/hello")
String simpleTrace2();
1
2
3
4
5

# PATCH 请求

使用@Patch注解或@PatchRequest注解

@Patch("http://localhost:8080/hello")
String simplePatch1();

@PatchRequest("http://localhost:8080/hello")
String simplePatch2();
1
2
3
4
5

# 动态 HTTP 请求方法

若不想在接口定义的时候直接定死为某个具体的 HTTP 请求方法,而是想从全局变量或方法参数中动态传入

可以使用 @Request 请求注解

/**
 * 通过在 @Request 注解的 type 属性中定义字符串模板
 * 在字符串模板中引用方法的参数
 */
@Request(
    url = "http://localhost:8080/hello",
    type = "{type}"
)
String simpleRequest(@Var("type") String type);
1
2
3
4
5
6
7
8
9

在调用改方法时通过参数传入 HTTP 请求方法类型(字符串类型,大小写不敏感)

// POST 请求
String result1 = simpleRequest("post");
// DELETE 请求
String result2 = simpleRequest("DELETE");
1
2
3
4
帮助我们改善此文档 (opens new window)
上次更新: 2023/03/07, 12:59:48
🧱 构建接口
🚚 请求地址

← 🧱 构建接口 🚚 请求地址→

Theme by Vdoing | Copyright © 2016-2023 公子骏 | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式