{"id":244,"date":"2024-03-01T11:27:49","date_gmt":"2024-03-01T03:27:49","guid":{"rendered":"https:\/\/blessingcr.com\/?p=244"},"modified":"2024-03-01T11:27:49","modified_gmt":"2024-03-01T03:27:49","slug":"api%e6%96%87%e6%a1%a3%e8%a7%84%e8%8c%83","status":"publish","type":"post","link":"https:\/\/blessingcr.com\/?p=244","title":{"rendered":"API\u6587\u6863\u89c4\u8303"},"content":{"rendered":"<h1>\u4ee5\u4e0b\u5c41\u8bdd\u90fd\u662f\u4e71\u8bf4\u7684\uff0c \u6211\u662f\u4e2a\u5fe0\u5b9e\u7684RESTful\u7528\u6237<\/h1>\n<h1>\u5efa\u8bae\u9075\u5faa <a href=\"https:\/\/cloud.google.com\/apis\/design?hl=zh-cn\">https:\/\/cloud.google.com\/apis\/design?hl=zh-cn<\/a><\/h1>\n<h1>\u4ee5\u4e0b\u5185\u5bb9\u4ec5\u4f9b\u7279\u6b8a\u60c5\u51b5\u4e0b\u4f7f\u7528<\/h1>\n<h1>API\u6587\u6863\u89c4\u8303<\/h1>\n<h3>API\u6587\u6863\u4f5c\u4e3a\u8be6\u7ec6\u8bbe\u8ba1\u7684\u4e00\u90e8\u5206\uff0c\u5176\u5fc5\u987b\u5728\u5f00\u53d1\u4e4b\u524d\u5b8c\u6210\u3002\u4e3a\u63d0\u9ad8\u524d\u540e\u7aef\u534f\u540c\u6548\u7387\uff0c\u8be6\u7ec6\u8bbe\u9636\u6bb5\u9700\u8981\u63d0\u4f9b\u6240\u6709\u524d\u540e\u7aef\u548c\u5bf9\u5916\u63a5\u53e3\uff1bRPC\u63a5\u53e3\u53ef\u540e\u7eed\u8865\u5145\uff1b<\/h3>\n<hr \/>\n<h3>0. \u901a\u7528\u89c4\u8303<\/h3>\n<p><strong>URL\u8981\u6c42<\/strong>\uff1a<\/p>\n<ol>\n<li>\u9700\u8981\u5305\u542b\u63a5\u53e3URL\uff08\u5177\u4f53\u57df\u540d\u6216IP\u53ef\u4e0d\u5199\uff09<\/li>\n<li>URL\u9700\u8981\u5305\u542b\u901a\u4fe1\u65b9\u5f0fhttp \/ https \/ ws \u7b49<\/li>\n<li>URL\u4f7f\u7528-\u8fde\u63a5\u591a\u4e2a\u5355\u8bcd<\/li>\n<li>\u5e38\u7528\u52a8\u8bcd\uff0c \u89c1\u4e0b\u52a8\u8bcd\u8868\uff0c\u52a8\u8bcd\u53ef\u81ea\u5b9a\u4e49\uff0c\u4f46curd\u7c7b\u529f\u80fd\u5982\u65e0\u7279\u6b8a\u60c5\u51b5\u8bf7\u53c2\u7167\u52a8\u8bcd\u8868\uff1b<\/li>\n<li>URL\u4e0d\u80fd\u5305\u542b\u7279\u6b8a\u5b57\u7b26\u548c\u654f\u611f\u8bcd\u6c47\uff0c\u9664\u975e\u8fd9\u4e9b\u5b57\u7b26\u6709\u7279\u6b8a\u7684\u7f16\u7801\u9700\u6c42<\/li>\n<li>\u5fc5\u987b\u5305\u542b\/api\/admin-api \u6216 \/api\/rpc-api<\/li>\n<li>url\u5e94\u8be5\u5b58\u5728\u5c42\u7ea7\u5173\u7cfb\uff0c\u9664\u56fa\u5b9a\u524d\u7f00\u5916\uff0c\u5e94\u4e3a\/\u9879\u76ee\u7b80\u79f0\/\u6a21\u5757\u540d\/[\u4e8c\u7ea7\u6a21\u5757\u540d\uff0c\u5982\u6709]\/\u529f\u80fd\u540d\/\u52a8\u8bcd\/[id, \u5982\u6709]<\/li>\n<\/ol>\n<table>\n<thead>\n<tr>\n<th>URL\u7ed3\u5c3e\u52a8\u8bcd<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>create<\/td>\n<td>\u521b\u5efa\u3001\u65b0\u589e<\/td>\n<\/tr>\n<tr>\n<td>update<\/td>\n<td>\u7f16\u8f91\u3001\u4fee\u6539<\/td>\n<\/tr>\n<tr>\n<td>delete<\/td>\n<td>\u5220\u9664<\/td>\n<\/tr>\n<tr>\n<td>get<\/td>\n<td>\u67e5\u8be2\u3001\u83b7\u53d6<\/td>\n<\/tr>\n<tr>\n<td>page<\/td>\n<td>\u5206\u9875\u67e5\u8be2<\/td>\n<\/tr>\n<tr>\n<td>export<\/td>\n<td>\u5bfc\u51fa<\/td>\n<\/tr>\n<tr>\n<td>import<\/td>\n<td>\u5bfc\u5165<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre><code class=\"language-java\">\u6837\u4f8b\uff1a\n- \u521b\u5efa\u89d2\u8272\uff1a\/admin-api\/cl\/acct\/role\/create\n- \u4fee\u6539\u89d2\u8272\uff1a\/admin-api\/cl\/acct\/role\/update\n- \u5220\u9664\u89d2\u8272\uff1a\/admin-api\/cl\/acct\/role\/delete\u3001 \/admin-api\/cl\/acct\/role\/delete\/{id}\n- \u83b7\u53d6\u89d2\u8272\u4fe1\u606f\uff1a\/admin-api\/cl\/acct\/role\/get\u3001\/admin-api\/cl\/acct\/role\/get\/{id}\u3001\/admin-api\/cl\/acct\/role\/get-by-user\n- \u83b7\u53d6\u89d2\u8272\u5206\u9875\uff1a\/admin-api\/cl\/acct\/role\/page\n- \u5bfc\u51fa\u89d2\u8272\uff1a\/admin-api\/cl\/acct\/role\/export\n- \u5bfc\u5165\u89d2\u8272\uff1a\/admin-api\/cl\/acct\/role\/import<\/code><\/pre>\n<p><strong>\u63a5\u53e3\u63cf\u8ff0\u8981\u6c42<\/strong>:<\/p>\n<ol>\n<li>\u5fc5\u987b\u5305\u542b\u529f\u80fd\u63cf\u8ff0<\/li>\n<li>\u52a0\u5bc6\u4e0e\u5426\uff0c\u7b7e\u540d\u4e0e\u5426 \uff0c\u5982\u6709\u9700\u8bf4\u660e\u52a0\u89e3\u5bc6\u65b9\u5f0f\u4e0e\u7b7e\u540d\u65b9\u5f0f<\/li>\n<li>\u5982\u6709\u7279\u6b8a\u9700\u8981\u6ce8\u610f\u7684\uff0c\u9700\u6ce8\u660e<\/li>\n<\/ol>\n<p><strong>\u8bf7\u6c42\u65b9\u5f0f\u8981\u6c42<\/strong>\uff1a<\/p>\n<ol>\n<li>\u76ee\u524d\u4ec5\u4f7f\u7528get \/ post\uff1b \u4e14\u5fc5\u987b\u5199\u660eget \/ post<\/li>\n<li>\u5bf9\u4e8e\u6d89\u53ca\u6570\u636e\u4fee\u6539\u7684\u64cd\u4f5c\uff08\u5982\u66f4\u65b0\uff0c\u5220\u9664\uff09\uff0c\u5e94\u4f7f\u7528POST\u8bf7\u6c42\u3002POST\u8bf7\u6c42\u53ef\u4ee5\u53d1\u9001\u5927\u91cf\u6570\u636e\uff0c\u4e14\u6570\u636e\u4e0d\u4f1a\u663e\u793a\u5728URL\u4e2d\uff0c\u7279\u522b\u7684\uff0c\u5206\u9875\u67e5\u8be2\u5e94\u4e3aPOST<\/li>\n<li>\u5bf9\u4e8e\u6570\u636e\u67e5\u8be2\u7684\u64cd\u4f5c\uff0c\u4e14\u65e0\u6d89\u53ca\u654f\u611f\u5185\u5bb9\uff0c\u5e94\u4f7f\u7528GET\u8bf7\u6c42<\/li>\n<li>\u6240\u6709GET\u8bf7\u6c42\u4e0d\u5e94\u8be5\u643a\u5e26body, \u907f\u514d\u4e2d\u95f4\u4ef6\u8fc7\u6ee4<\/li>\n<\/ol>\n<p><strong>\u8bf7\u6c42\u5b57\u6bb5\u8981\u6c42<\/strong>\uff1a<\/p>\n<ol>\n<li>\u8bf7\u6c42\u53c2\u6570\uff0c\u5305\u62echeader\u4e0ebody\uff0c\u53c2\u6570\u9700\u8981\u5199\u660e\u5fc5\u586b\u3001\u7c7b\u578b\u3001\u957f\u5ea6\u548c\u610f\u4e49\uff0c\u5982\u9700\u8ba1\u7b97\u5199\u660e\u8ba1\u7b97\u89c4\u5219<\/li>\n<li>\u5982\u6d89\u53ca\u5e38\u91cf\uff0c\u5219\u5fc5\u987b\u63cf\u8ff0\u6240\u6709\u5e38\u91cf\u53ca\u5176\u610f\u4e49<\/li>\n<li>\u6d89\u53ca\u524d\u540e\u7aef\u4f20\u53c2\u6216\u5bf9\u5916\u63a5\u53e3\u65f6\uff0cLong\u7c7b\u578b\u5b57\u6bb5\u5fc5\u987b\u4f7f\u7528String\u7c7b\u578b\u907f\u514d\u7cbe\u5ea6\u4e22\u5931<\/li>\n<li>\u5b57\u6bb5\u7684\u547d\u540d\u5e94\u9075\u5faa\u9a7c\u5cf0\u547d\u540d\u6cd5<\/li>\n<li>\u7f16\u7801\u4f7f\u7528UTF-8<\/li>\n<\/ol>\n<p><strong>\u54cd\u5e94\u8981\u6c42<\/strong>\uff1a<\/p>\n<ol>\n<li>\u54cd\u5e94\u53c2\u6570\uff0c\u53c2\u6570\u9700\u8981\u5199\u660e\u5fc5\u586b\u3001\u7c7b\u578b\u3001\u957f\u5ea6\u3001\u610f\u4e49\u548cmock\u503c\uff0c\u5982\u9700\u8ba1\u7b97\u5199\u660e\u8ba1\u7b97\u89c4\u5219<\/li>\n<li>\u5fc5\u987b\u5305\u542bcode, data, msg\u5b57\u6bb5\uff1b \u5176\u4e2ddata\u4e3a\u7a7a\u7684\u65f6\u5019\u8bbe\u7f6e\u4e3a{}\uff0c\u4e0d\u53ef\u4e3anull\uff1b code\u6b63\u5e38\u662f\u4e3a0\uff0c\u5176\u4f59\u60c5\u51b5\u4e0b\u4e3a\u9519\u8bef\u7801<\/li>\n<li>\u65e0\u7279\u522b\u8bbe\u8ba1\u65f6\uff0c\u76f8\u5e94\u6b63\u5e38\u4ee5\u53ca\u4e1a\u52a1\u5f02\u5e38\u65f6\uff0cHTTP STATUS\u5747\u4e3a200\uff1b \u5982\u7279\u6b8a\u60c5\u51b5\uff0c\u9700\u6ce8\u660e<\/li>\n<li>\u7f16\u7801\u4f7f\u7528UTF-8<\/li>\n<\/ol>\n<hr \/>\n<h3>1. \u5185\u90e8\u975e\u524d\u540e\u7aef\u63a5\u53e3\u6587\u6863\u989d\u5916\u89c4\u8303\uff08\u5305\u62ec\u4f46\u4e0d\u9650\u4e8eRPC, MQ\u7b49\uff09<\/h3>\n<p>MQ\u7c7b:<\/p>\n<ol>\n<li>\u5fc5\u987b\u5199\u660eTopic\uff0c \u6d88\u606f\u7c7b\u578b\uff0cTAG\u7b49\u57fa\u7840\u4fe1\u606f<\/li>\n<li>\u5982\u6709\u52a0\u89e3\u5bc6\u65b9\u5f0f\uff0c\u5fc5\u987b\u5199\u660e<\/li>\n<li>\u5199\u660e\u6d88\u606f\u4f53\uff0c\u4ee5\u53ca\u6d88\u606f\u5185\u5177\u4f53\u5b57\u6bb5\u542b\u4e49<\/li>\n<li>\u5efa\u8bae\u4f7f\u7528@link \u5173\u8054\u6d89\u53ca\u7684producer\uff0c consumer<\/li>\n<\/ol>\n<p>RPC\u7c7b\uff1a<\/p>\n<ol>\n<li>\u63a8\u8350\u5728url\u4e2d\u52a0\u4e0a\u63a5\u53e3\u7248\u672c<\/li>\n<li>\u5982\u679cheader\u4e2d\u9700\u8981\u7279\u6b8a\u53c2\u6570\uff0c\u5fc5\u987b\u8bf4\u660e<\/li>\n<li>\u8fd4\u56de\u503c\u5e94\u7528CommonResult\u5305\u88f9\uff0c\u7279\u6b8a\u6bd4\u7279\u6d41\u8fd4\u56de\u7b49\u9664\u5916<\/li>\n<li>\u5f02\u6b65\u63a5\u53e3\u9700\u8981\u7279\u6b8a\u6ce8\u660e\uff0c\u5982\u63d0\u4f9b\u540e\u7eed\u67e5\u8be2\u7ed3\u679c\u63a5\u53e3\uff0c\u6ce8\u660e<\/li>\n<li>\u5982\u679c\u4e3a\u6279\u91cf\u63a5\u53e3\uff0c\u4f7f\u7528\u5217\u8868\u6216\u8005\u5176\u4ed6\u96c6\u5408\u7c7b\u5305\u88f9\u6240\u6709\u7ed3\u679c\uff0c\u4e0d\u8981\u6709\u4efb\u4e00\u5143\u7d20\u76f4\u63a5\u5931\u8d25\u8fd4\u56de\u6574\u4f53\u5931\u8d25\u3002<\/li>\n<\/ol>\n<hr \/>\n<h3>2. \u5916\u90e8\u63a5\u53e3\u6587\u6863\u989d\u5916\u89c4\u8303<\/h3>\n<p>\u5f3a\u5236\u8981\u6c42\uff1a<\/p>\n<ol>\n<li>\u6bcf\u4e2a\u63a5\u53e3\u5fc5\u987b\u5305\u542b\uff1a\n<ol>\n<li>\u529f\u80fd\u63cf\u8ff0<\/li>\n<li>\u901a\u4fe1\u65b9\u5f0f \u2014\u2014 [https, http, tpc, websocket\u7b49]<\/li>\n<li>\u6570\u636e\u683c\u5f0f \u2014\u2014[json, xml\u7b49]<\/li>\n<li>\u8bf7\u6c42\u793a\u4f8b\u4e0e\u54cd\u5e94\u5b9e\u4f8b<\/li>\n<li>\u6709\u53ef\u80fd\u8fd4\u56de\u7684\u9519\u8bef\u7801\u53ca\u5176\u542b\u4e49<\/li>\n<li>SDK\uff08\u5982\u6709\uff09<\/li>\n<\/ol>\n<\/li>\n<li>\u5bf9\u5916HTTP\u63a5\u53e3\u5f3a\u5236\u8981\u6c42HTTPS<\/li>\n<li>\u6d89\u53ca\u654f\u611f\u5b57\u6bb5\u4f20\u8f93\u5fc5\u987b\u4f7f\u7528POST\uff0c \u4e14\u8003\u8651\u52a0\u5bc6\u4f20\u8f93<\/li>\n<li>\u91d1\u94b1\u7c7b\u53c2\u6570\u5fc5\u987b\u4f7f\u7528String\u7c7b\u578b\u4f20\u8f93<\/li>\n<li>\u65f6\u95f4\u4f20\u8f93\u5982\u679c\u4f7f\u7528String\u7c7b\u578b\uff0c\u9700\u8981\u8bf4\u660e\u65f6\u533a<\/li>\n<li>mock\u5b57\u6bb5\u53c2\u6570\u6216\u7ed3\u679c\uff0c\u4e0d\u5e94\u8be5\u51fa\u73b0\u771f\u5b9e\u7684\u540d\u79f0\uff0c\u4f46\u53ef\u4ee5\u662f\u672c\u516c\u53f8\u6216\u8005\u5408\u4f5c\u516c\u53f8\u540d\u79f0 <\/li>\n<\/ol>\n<p>\u63a8\u8350\u8981\u6c42\uff1a<\/p>\n<ol>\n<li>\u63a8\u8350\u5305\u542b\uff1a\n<ol>\n<li>\u5bf9\u63a5\u51c6\u5907<\/li>\n<li>\u5feb\u901f\u5165\u95e8<\/li>\n<li>\u5404\u5177\u4f53\u573a\u666f\u4e0b\u4e1a\u52a1\u65b9\u6848 \/ \u98ce\u63a7\u65b9\u6848 \/ \u63a8\u8350\u914d\u7f6e<\/li>\n<li>\u63a5\u53e3\u4e4b\u95f4\u7684\u65f6\u5e8f\u56fe\/\u6d41\u7a0b\u56fe<\/li>\n<li>\u5404\u8bed\u8a00\u8c03\u7528\u63a5\u53e3\u7684\u6837\u4f8b\u4ee3\u7801 \/ Postman\u9879\u76ee\u6587\u4ef6<\/li>\n<li>\u670d\u52a1\u652f\u6301\u534f\u8bae<\/li>\n<li>\u5e38\u89c1\u95ee\u9898<\/li>\n<li>\u7248\u672c\u53f7\u4e0e\u7248\u672c\u8bf4\u660e<\/li>\n<\/ol>\n<\/li>\n<li>header\u4e2d\uff0c\u5982\u7279\u522b\u4e0d\u9700cdn\u7f13\u5b58\u7684\u63a5\u53e3\uff0c\u63a8\u8350\u52a0\u4e0acache-control<\/li>\n<li>\u4e0d\u63a8\u8350\u8fd4\u56de\u8de8\u57dfheader\u4e3a*<\/li>\n<li>\u63a8\u8350\u4f7f\u7528\/v1,\/v2\u4e4b\u7c7b\u7684\u5f85\u7248\u672c\u53f7\u7684url\uff0c\u7528\u4e8e\u540c\u65f6\u652f\u6301\u591a\u7248\u672c\u670d\u52a1<\/li>\n<\/ol>\n<hr \/>\n<h3>\u9644\u5f55\u6807\u51c6\u5b57\u6bb5<\/h3>\n<p>\u672c\u8282\u4ecb\u7ecd\u4e86\u9700\u8981\u7c7b\u4f3c\u6982\u5ff5\u65f6\u5e94\u4f7f\u7528\u7684\u4e00\u7ec4\u6807\u51c6\u6d88\u606f\u5b57\u6bb5\u5b9a\u4e49\u3002\u8fd9\u5c06\u786e\u4fdd\u76f8\u540c\u7684\u6982\u5ff5\u5728\u4e0d\u540c API \u4e2d\u5177\u6709\u76f8\u540c\u7684\u540d\u79f0\u548c\u8bed\u4e49\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee5\u4e0b\u5c41\u8bdd\u90fd\u662f\u4e71\u8bf4\u7684\uff0c \u6211\u662f\u4e2a\u5fe0\u5b9e\u7684RESTful\u7528\u6237 \u5efa\u8bae\u9075\u5faa https:\/\/cloud.google.co [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[74],"tags":[84],"class_list":["post-244","post","type-post","status-publish","format-standard","hentry","category-74","tag-api"],"_links":{"self":[{"href":"https:\/\/blessingcr.com\/index.php?rest_route=\/wp\/v2\/posts\/244","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blessingcr.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blessingcr.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blessingcr.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blessingcr.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=244"}],"version-history":[{"count":1,"href":"https:\/\/blessingcr.com\/index.php?rest_route=\/wp\/v2\/posts\/244\/revisions"}],"predecessor-version":[{"id":245,"href":"https:\/\/blessingcr.com\/index.php?rest_route=\/wp\/v2\/posts\/244\/revisions\/245"}],"wp:attachment":[{"href":"https:\/\/blessingcr.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blessingcr.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blessingcr.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}