{"id":779,"date":"2025-04-26T15:14:44","date_gmt":"2025-04-26T06:14:44","guid":{"rendered":"https:\/\/hirabay.net\/?p=779"},"modified":"2025-04-26T15:14:48","modified_gmt":"2025-04-26T06:14:48","slug":"%e3%80%90httpinterface%e6%b4%bb%e7%94%a8%e3%80%91%e3%82%82%e3%81%86xxxrequest%e3%81%a8%e3%81%8bxxxxresponse%e3%81%a8%e3%81%8bxxxapiclinet%e3%81%af%e5%ae%9f%e8%a3%85%e4%b8%8d%e8%a6%81%ef%bc%81","status":"publish","type":"post","link":"https:\/\/hirabay.net\/?p=779","title":{"rendered":"\u3010HttpInterface\u6d3b\u7528\u3011\u3082\u3046XxxRequest\u3068\u304bXxxxResponse\u3068\u304bXxxApiClinet\u306f\u5b9f\u88c5\u4e0d\u8981\uff01"},"content":{"rendered":"\n<p>API\u3068\u306e\u901a\u4fe1\u3092\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u3001\u8a72\u5f53\u306eAPI\u3068\u3084\u308a\u3068\u308a\u3059\u308b\u305f\u3081\u5c02\u7528\u306eXxxApiClient\u3068\u304b\u30ea\u30af\u30a8\u30b9\u30c8\u30fb\u30ec\u30b9\u30dd\u30f3\u30b9\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u304b\u3092\u5b9a\u7fa9\u3057\u306a\u3044\u3068\u3044\u3051\u307e\u305b\u3093\u3002<\/p>\n\n\n\n<p>\u3051\u3069\u3001\u4e16\u306b\u51fa\u3066\u3044\u308b\u3007\u3007\u30e9\u30a4\u30d6\u30e9\u30ea\u3063\u3066\u30ea\u30af\u30a8\u30b9\u30c8\u3084\u30ec\u30b9\u30dd\u30f3\u30b9\u3082\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u4e2d\u306b\u5165\u3063\u3066\u3044\u3066\u3001\u63a5\u7d9a\u60c5\u5831\u3092\u8a2d\u5b9a\u3059\u308b\u304f\u3089\u3044\u3067\u4f7f\u3048\u3066\u4fbf\u5229\u3067\u3059\u3002<\/p>\n\n\n\n<p>SpringBoot\u3067\u3082HttpInterface\u3092\u5229\u7528\u3059\u308b\u3068\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u914d\u308b\u3053\u3068\u3067\u540c\u3058\u3088\u3046\u306a\u4e16\u754c\u89b3\u3092\u5b9f\u73fe\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\uff01<\/p>\n\n\n\n<div class=\"toc\"><br \/>\n<b>Warning<\/b>:  Undefined array key \"is_admin\" in <b>\/home\/c4179872\/public_html\/hirabay.net\/wp-content\/themes\/sango-theme\/library\/gutenberg\/dist\/classes\/Toc.php<\/b> on line <b>110<\/b><br \/>\n<br \/>\n<b>Warning<\/b>:  Undefined array key \"is_category_top\" in <b>\/home\/c4179872\/public_html\/hirabay.net\/wp-content\/themes\/sango-theme\/library\/gutenberg\/dist\/classes\/Toc.php<\/b> on line <b>115<\/b><br \/>\n<br \/>\n<b>Warning<\/b>:  Undefined array key \"is_top\" in <b>\/home\/c4179872\/public_html\/hirabay.net\/wp-content\/themes\/sango-theme\/library\/gutenberg\/dist\/classes\/Toc.php<\/b> on line <b>122<\/b><br \/>\n    <div id=\"toc_container\" class=\"sgb-toc--bullets js-smooth-scroll\">\n      <p class=\"toc_title\">\u76ee\u6b21 <\/p>\n      <ul class=\"toc_list\">\n  <li class=\"first\">\n    <a href=\"#i-0\">\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u4f5c\u6210<\/a>\n  <\/li>\n  <li>\n    <a href=\"#i-1\">\u30b5\u30fc\u30d0\u306e\u5b9f\u88c5<\/a>\n  <\/li>\n  <li class=\"last\">\n    <a href=\"#i-2\">\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306e\u5b9f\u88c5<\/a>\n  <\/li>\n<\/ul>\n\n      \n    <\/div><\/div><h2 class=\"wp-block-heading\" id=\"i-0\">\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u4f5c\u6210<\/h2>\n\n\n\n<p>\u307e\u305a\u306f\u30d9\u30fc\u30b9\u3068\u306a\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u4f5c\u6210\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3092Client\u3067\u3082Server\u3067\u3082\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>RestController\u3067\u30b5\u30fc\u30d0\u5074\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u5b9a\u7fa9\u3059\u308b\u3088\u3046\u306a\u611f\u3058\u3067\u5b9f\u88c5\u3057\u3066\u3044\u3051\u3070\u826f\u3044\u306e\u3067\u3059\u304c\u3001<br><code>@HttpExchange<\/code> \u3068\u3044\u3063\u305f<a href=\"https:\/\/docs.spring.io\/spring-framework\/reference\/integration\/rest-clients.html#rest-http-interface\">Http Interface\u5c02\u7528\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3<\/a>\u3092\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-sgb-tab\"><div class=\"post-tab cf\"><label class=\"tab1 tab-active\">Java<\/label><label class=\"tab2\">Kotlin<\/label><\/div>\n<div class=\"wp-block-sgb-tab-item post-tab__content tab1 tab-active\">\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-java\" data-lang=\"Java\"><code>@HttpExchange(\"\/api\")\npublic interface SampleApiInterface {\n    @PostExchange(\"\/sample\")\n    SampleApiResponse sample(@RequestBody SampleApiRequest request);\n}\n\npublic record SampleApiRequest(String message) {\n}\n\npublic record SampleApiResponse(String result) {\n}<\/code><\/pre><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-sgb-tab-item post-tab__content tab2\">\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-kotlin\" data-lang=\"Kotlin\"><code>@HttpExchange(\"\/api\/kt\")\ninterface SampleApiInterfaceKt {\n    @PostExchange(\"\/sample\")\n    fun sample(@RequestBody request: SampleApiRequestKt): SampleApiResponseKt\n}\n\ndata class SampleApiRequestKt(\n    val message: String,\n)\n\ndata class SampleApiResponseKt(\n    val result: String,\n)<\/code><\/pre><\/div>\n<\/div>\n<\/div>\n\n\n\n<p>\u3042\u3068\u306f\u30e9\u30a4\u30d6\u30e9\u30ea\u3068\u3057\u3066Maven Repository\u7b49\u306b\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u4f5c\u308a\u65b9\u306f\u4ee5\u4e0b\u3082\u3054\u53c2\u8003\u306b\uff01<\/p>\n\n\n<a class=\"linkto table\" href=\"https:\/\/hirabay.net\/?p=446\"><span class=\"tbcell tbimg\"><img loading=\"lazy\" decoding=\"async\" width=\"160\" height=\"160\" src=\"https:\/\/hirabay.net\/wp-content\/uploads\/2023\/02\/1907d11cd17a088c79918806990055e4-160x160.png\" class=\"attachment-thumb-160 size-thumb-160 wp-post-image\" alt=\"\" srcset=\"https:\/\/hirabay.net\/wp-content\/uploads\/2023\/02\/1907d11cd17a088c79918806990055e4-160x160.png 160w, https:\/\/hirabay.net\/wp-content\/uploads\/2023\/02\/1907d11cd17a088c79918806990055e4-150x150.png 150w\" sizes=\"auto, (max-width: 160px) 100vw, 160px\"><\/span><span class=\"tbcell tbtext\"><time class=\"pubdate sng-link-time dfont\" itemprop=\"datePublished\" datetime=\"2023-02-12\">2023\u5e742\u670812\u65e5<\/time>\u3010Gradle \u00d7 Java\u3011\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u4f5c\u308a\u65b9<\/span><\/a>\n\n\n<h2 class=\"wp-block-heading\" id=\"i-1\">\u30b5\u30fc\u30d0\u306e\u5b9f\u88c5<\/h2>\n\n\n\n<p>\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3001\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u3084\u30ea\u30af\u30a8\u30b9\u30c8\u30fb\u30ec\u30b9\u30dd\u30f3\u30b9\u30af\u30e9\u30b9\u304c\u5b9a\u7fa9\u6e08\u307f\u306a\u306e\u3067\u3001<br>API\u306e\u52d5\u4f5c\u306e\u90e8\u5206\u306b\u96c6\u4e2d\u3057\u3066\u5b9f\u88c5\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\uff01<\/p>\n\n\n\n<div class=\"wp-block-sgb-tab\"><div class=\"post-tab cf\"><label class=\"tab1 tab-active\">Java<\/label><label class=\"tab2\">Kotlin<\/label><\/div>\n<div class=\"wp-block-sgb-tab-item post-tab__content tab1 tab-active\">\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-java\" data-lang=\"Java\"><code>@RestController\npublic class SampleApiController implements SampleApiInterface {\n    @Override\n    public SampleApiResponse sample(SampleApiRequest request) {\n        return new SampleApiResponse(\"Hello, \" + request.message());\n    }\n}<\/code><\/pre><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-sgb-tab-item post-tab__content tab2\">\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-kotlin\" data-lang=\"Kotlin\"><code>@RestController\nclass SampleApiControllerKt: SampleApiInterfaceKt {\n    override fun sample(request: SampleApiRequestKt): SampleApiResponseKt {\n        return SampleApiResponseKt(\"Hello, ${request.message}\")\n    }\n}<\/code><\/pre><\/div>\n<\/div>\n<\/div>\n\n\n\n<p>\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u5b9f\u88c5\u3057\u305finterface\u3092\u5b9f\u88c5\u3059\u308b\u4ee5\u5916\u306f\u666e\u901a\u306eController\u3068\u4e00\u7dd2\u3067\u3059\uff01<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-2\">\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306e\u5b9f\u88c5<\/h2>\n\n\n\n<p>HttpServiceProxyFactory\u306b\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u4f5c\u6210\u3057\u305finterface\u3092\u6e21\u3059\u3060\u3051\uff01<\/p>\n\n\n\n<p>RestClient\u3068\u304bWebClient\u3068\u304b\u3067\u63a5\u7d9a\u5148\u3084\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u7b49\u3092\u8a2d\u5b9a\u3059\u308b\u90e8\u5206\u3060\u3051\u306b\u96c6\u4e2d\u3067\u304d\u307e\u3059\uff01<\/p>\n\n\n\n<div class=\"wp-block-sgb-tab\"><div class=\"post-tab cf\"><label class=\"tab1 tab-active\">Java<\/label><label class=\"tab2\">Kotlin<\/label><\/div>\n<div class=\"wp-block-sgb-tab-item post-tab__content tab1 tab-active\">\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-java\" data-lang=\"Java\"><code>@Configuration\npublic class SampleApiClientConfiguration {\n    @Bean\n    public SampleApiInterface sampleClient() {\n        var restClient = RestClient.builder()\n                .baseUrl(\"http:\/\/localhost:8080\/\")\n                .build();\n        var adapter = RestClientAdapter.create(restClient);\n        var factory = HttpServiceProxyFactory.builderFor(adapter).build();\n        return factory.createClient(SampleApiInterface.class);\n    }\n}<\/code><\/pre><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-sgb-tab-item post-tab__content tab2\">\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-kotlin\" data-lang=\"Kotlin\"><code>@Configuration\nclass SampleApiClientConfigurationKt {\n    @Bean\n    fun sampleApiClientKt(): SampleApiInterfaceKt {\n        val restClient = RestClient.builder()\n            .baseUrl(\"http:\/\/localhost:8080\/\")\n            .build()\n        val adapter = RestClientAdapter.create(restClient)\n        val factory = HttpServiceProxyFactory.builderFor(adapter).build()\n\n        return factory.createClient(SampleApiInterfaceKt::class.java)\n    }\n}<\/code><\/pre><\/div>\n<\/div>\n<\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>API\u3068\u306e\u901a\u4fe1\u3092\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u3001\u8a72\u5f53\u306eAPI\u3068\u3084\u308a\u3068\u308a\u3059\u308b\u305f\u3081\u5c02\u7528\u306eXxxApiClient\u3068\u304b\u30ea\u30af\u30a8\u30b9\u30c8\u30fb\u30ec\u30b9\u30dd\u30f3\u30b9\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u304b\u3092\u5b9a\u7fa9\u3057\u306a\u3044\u3068\u3044\u3051\u307e\u305b\u3093\u3002 \u3051\u3069\u3001\u4e16\u306b\u51fa\u3066\u3044\u308b\u3007\u3007\u30e9\u30a4\u30d6\u30e9\u30ea\u3063\u3066\u30ea\u30af\u30a8\u30b9\u30c8\u3084\u30ec\u30b9\u30dd\u30f3\u30b9 &#8230; <\/p>\n","protected":false},"author":1,"featured_media":782,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[115,13],"class_list":{"0":"post-779","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-6","8":"tag-http-interface","9":"tag-springboot"},"jetpack_featured_media_url":"https:\/\/hirabay.net\/wp-content\/uploads\/2025\/04\/SpringBoot.png","_links":{"self":[{"href":"https:\/\/hirabay.net\/index.php?rest_route=\/wp\/v2\/posts\/779","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hirabay.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hirabay.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hirabay.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hirabay.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=779"}],"version-history":[{"count":2,"href":"https:\/\/hirabay.net\/index.php?rest_route=\/wp\/v2\/posts\/779\/revisions"}],"predecessor-version":[{"id":784,"href":"https:\/\/hirabay.net\/index.php?rest_route=\/wp\/v2\/posts\/779\/revisions\/784"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hirabay.net\/index.php?rest_route=\/wp\/v2\/media\/782"}],"wp:attachment":[{"href":"https:\/\/hirabay.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=779"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hirabay.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=779"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hirabay.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=779"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}