magic-api magic-api
首页
  • 快速入门
  • 基础教程
  • 权限配置
  • 高级应用
  • 开发插件
  • 模块
  • 函数
  • 扩展
  • Gitee (opens new window)
  • Github (opens new window)
  • 演示 (opens new window)
  • SpringBoot配置
  • 编辑器配置
  • 2.x更新日志
  • 1.x更新日志
  • 0.x更新日志
常见问题
💖支持
交流群
首页
  • 快速入门
  • 基础教程
  • 权限配置
  • 高级应用
  • 开发插件
  • 模块
  • 函数
  • 扩展
  • Gitee (opens new window)
  • Github (opens new window)
  • 演示 (opens new window)
  • SpringBoot配置
  • 编辑器配置
  • 2.x更新日志
  • 1.x更新日志
  • 0.x更新日志
常见问题
💖支持
交流群
  • 模块

    • db模块
    • http模块
      • 模块说明
      • 引用模块
      • connect
      • 设置URL参数
      • 设置表单参数
      • 设置Header
      • body
      • entity
      • contentType
      • post
      • delete
      • get
      • put
      • head
      • patch
      • options
      • trace
      • execute
    • log模块
    • request模块
    • response模块
    • env模块
    • magic模块
  • 函数

    • 聚合函数
    • 日期函数
    • 字符串函数
    • 数组函数
    • 数学函数
    • 其它函数
  • 扩展

    • Object
    • Number
    • 数组&集合
    • Date
    • Class
    • Pattern
  • API
  • 模块
mxd
2022-01-30
目录

http模块

# 模块说明

http模块是基于RestTemplate封装而来,目前只做了少量的封装。 对于一些通用的配置可以使用自定义RestTemplate来实现

@Bean
public HttpModule magicHttpModule() {
	RestTemplate template = new RestTemplate();
	// 对RestTemplate进行配置.
    // your code
	return new HttpModule(template);
}

# 引用模块

import http;

# connect

  • 入参:url:string
  • 返回值:HttpModule
  • 函数说明:创建新的http请求对象
import http;
http.connect("http://localhost:9999/sql/select") 

# 设置URL参数

# 设置表单参数

# 设置Header

import http;
http.param('url_param1','url_param_value1') // 设置URL参数
    .param({    // 批量设置URL参数
        url_param_2 : 2,
        url_param_3 : 3,
    })
    .data('form_param1','form_param_value1') // 设置表单参数
    .data({    // 批量设置表单参数
        form_param_2 : 2,
        form_param_3 : 3,
    })
    .header('header_param1','header_param_value1') // 设置header参数
    .header({    // 批量设置header参数
        header_param_2 : 2,
        header_param_3 : 3,
    })

# body

  • 入参:body:Object
  • 函数说明:获取请求Body
import http;
http.connect('..').body({
    id: 1,
    name: 'magic-api'
});

# entity

  • 入参: entity: HttpEntity
  • 函数说明:自定义HttpEntity
import http;
http.connect('..').entity(entity)

# contentType

  • 入参: contentType: String或MediaType
  • 函数说明:定义请求内容类型
import http;
http.connect('..').contentType('application/json')

# post

# delete

# get

# put

# head

# patch

# options

# trace

# execute

  • 返回值:ResponseEntity
  • 函数说明:执行对应的请求,post会自动设置为POST请求,其它同理
import http;
return http.connect('http://localhost:9999/sql/select').post().getBody()
上次更新: 2025-05-03 23:57:14
db模块
log模块

← db模块 log模块→

Theme by Vdoing | Copyright © 2020-2025 ssssssss.org | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×