关于自定义API #4277
Answered
by
guqing
MoritzArena
asked this question in
Q&A
关于自定义API
#4277
-
如自定义模型|Halo 文档所示的自定义API编写方法,我在插件中定义了以下的接口: @ApiVersion("v1alpha1")
@RestController
public class GraphQLRouter {
@Resource
private GraphQLReader reader;
@Resource
private SettingFetcher settingFetcher;
// this controller we use full reactive stream
@PostMapping("/graphql")
public Mono<String> sayHello(@RequestParam String url,
@RequestParam String graphql,
@RequestParam String variables) {
return settingFetcher
.fetch("basic", SettingsReader.class)
.map(config -> WebClient.builder()
// we can use https://api.github.com/graphql for test unit
.baseUrl(url)
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.defaultHeader(HttpHeaders.AUTHORIZATION, "token " + config.getGithubToken())
.build()
.post()
.bodyValue(Map.of(
"query", reader.getGraphQL(graphql),
"variables", reader.getVariables(variables)
))
.retrieve()
.bodyToMono(String.class))
.orElse(Mono.just("can't get result from " + url));
}
} 这在本地的测试环境中是能通过swagger请求测试的,也返回了我预期的内容,当迁移到正式环境后再请求该接口会出现404的问题,同样的我也尝试了axios、fetch来获取接口的返回内容但都无一例外的都是404问题,这是其中一个请求的响应体:
请问是需要对接口做其他的设置才能正常暴露到前端吗? |
Beta Was this translation helpful? Give feedback.
Answered by
guqing
Jul 21, 2023
Replies: 1 comment 1 reply
-
我看你 API 写的 是 |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
guqing
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
我看你 API 写的 是
/graphql
为什么你访问的是/graphql/github