{"id":10529,"date":"2023-04-07T20:16:04","date_gmt":"2023-04-07T12:16:04","guid":{"rendered":"http:\/\/123.57.164.21\/?p=10529"},"modified":"2023-04-07T20:16:04","modified_gmt":"2023-04-07T12:16:04","slug":"%e7%90%86%e8%a7%a3restful","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=10529","title":{"rendered":"\u7406\u89e3RESTful"},"content":{"rendered":"\n<p><strong>\u4e00\u3001\u7406\u89e3RESTful\u67b6\u6784<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u8d8a\u6765\u8d8a\u591a\u7684\u4eba\u5f00\u59cb\u610f\u8bc6\u5230\uff0c\u7f51\u7ad9\u5373\u8f6f\u4ef6\uff0c\u800c\u4e14\u662f\u4e00\u79cd\u65b0\u578b\u7684\u8f6f\u4ef6\u3002<\/p>\n\n\n\n<p>\u8fd9\u79cd&#8221;\u4e92\u8054\u7f51\u8f6f\u4ef6&#8221;\u91c7\u7528\u5ba2\u6237\u7aef\/\u670d\u52a1\u5668\u6a21\u5f0f\uff0c\u5efa\u7acb\u5728\u5206\u5e03\u5f0f\u4f53\u7cfb\u4e0a\uff0c\u901a\u8fc7\u4e92\u8054\u7f51\u901a\u4fe1\uff0c\u5177\u6709\u9ad8\u5ef6\u65f6\uff08high latency\uff09\u3001\u9ad8\u5e76\u53d1\u7b49\u7279\u70b9\u3002<\/p>\n\n\n\n<p>\u7f51\u7ad9\u5f00\u53d1\uff0c\u5b8c\u5168\u53ef\u4ee5\u91c7\u7528\u8f6f\u4ef6\u5f00\u53d1\u7684\u6a21\u5f0f\u3002\u4f46\u662f\u4f20\u7edf\u4e0a\uff0c\u8f6f\u4ef6\u548c\u7f51\u7edc\u662f\u4e24\u4e2a\u4e0d\u540c\u7684\u9886\u57df\uff0c\u5f88\u5c11\u6709\u4ea4\u96c6\uff1b\u8f6f\u4ef6\u5f00\u53d1\u4e3b\u8981\u9488\u5bf9\u5355\u673a\u73af\u5883\uff0c\u7f51\u7edc\u5219\u4e3b\u8981\u7814\u7a76\u7cfb\u7edf\u4e4b\u95f4\u7684\u901a\u4fe1\u3002\u4e92\u8054\u7f51\u7684\u5174\u8d77\uff0c\u4f7f\u5f97\u8fd9\u4e24\u4e2a\u9886\u57df\u5f00\u59cb\u878d\u5408\uff0c\u73b0\u5728\u6211\u4eec\u5fc5\u987b\u8003\u8651\uff0c\u5982\u4f55\u5f00\u53d1\u5728\u4e92\u8054\u7f51\u73af\u5883\u4e2d\u4f7f\u7528\u7684\u8f6f\u4ef6\u3002<\/p>\n\n\n\n<p>RESTful\u67b6\u6784\uff0c\u5c31\u662f\u76ee\u524d\u6700\u6d41\u884c\u7684\u4e00\u79cd\u4e92\u8054\u7f51\u8f6f\u4ef6\u67b6\u6784\u3002\u5b83\u7ed3\u6784\u6e05\u6670\u3001\u7b26\u5408\u6807\u51c6\u3001\u6613\u4e8e\u7406\u89e3\u3001\u6269\u5c55\u65b9\u4fbf\uff0c\u6240\u4ee5\u6b63\u5f97\u5230\u8d8a\u6765\u8d8a\u591a\u7f51\u7ad9\u7684\u91c7\u7528\u3002<\/p>\n\n\n\n<p>\u4f46\u662f\uff0c\u5230\u5e95\u4ec0\u4e48\u662fRESTful\u67b6\u6784\uff0c\u5e76\u4e0d\u662f\u4e00\u4e2a\u5bb9\u6613\u8bf4\u6e05\u695a\u7684\u95ee\u9898\u3002\u4e0b\u9762\uff0c\u6211\u5c31\u8c08\u8c08\u6211\u7406\u89e3\u7684RESTful\u67b6\u6784\u3002<\/p>\n\n\n\n<p><strong>1.1\u3001\u8d77\u6e90<\/strong><\/p>\n\n\n\n<p>Fielding\u662f\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u4eba\uff0c\u4ed6\u662fHTTP\u534f\u8bae\uff081.0\u7248\u548c1.1\u7248\uff09\u7684\u4e3b\u8981\u8bbe\u8ba1\u8005\u3001Apache\u670d\u52a1\u5668\u8f6f\u4ef6\u7684\u4f5c\u8005\u4e4b\u4e00\u3001Apache\u57fa\u91d1\u4f1a\u7684\u7b2c\u4e00\u4efb\u4e3b\u5e2d\u3002\u6240\u4ee5\uff0c\u4ed6\u7684\u8fd9\u7bc7\u8bba\u6587\u4e00\u7ecf\u53d1\u8868\uff0c\u5c31\u5f15\u8d77\u4e86\u5173\u6ce8\uff0c\u5e76\u4e14\u7acb\u5373\u5bf9\u4e92\u8054\u7f51\u5f00\u53d1\u4ea7\u751f\u4e86\u6df1\u8fdc\u7684\u5f71\u54cd\u3002<\/p>\n\n\n\n<p>\u4ed6\u8fd9\u6837\u4ecb\u7ecd\u8bba\u6587\u7684\u5199\u4f5c\u76ee\u7684\uff1a<\/p>\n\n\n\n<p>&#8220;\u672c\u6587\u7814\u7a76\u8ba1\u7b97\u673a\u79d1\u5b66\u4e24\u5927\u524d\u6cbf&#8212;-\u8f6f\u4ef6\u548c\u7f51\u7edc&#8212;-\u7684\u4ea4\u53c9\u70b9\u3002\u957f\u671f\u4ee5\u6765\uff0c\u8f6f\u4ef6\u7814\u7a76\u4e3b\u8981\u5173\u6ce8\u8f6f\u4ef6\u8bbe\u8ba1\u7684\u5206\u7c7b\u3001\u8bbe\u8ba1\u65b9\u6cd5\u7684\u6f14\u5316\uff0c\u5f88\u5c11\u5ba2\u89c2\u5730\u8bc4\u4f30\u4e0d\u540c\u7684\u8bbe\u8ba1\u9009\u62e9\u5bf9\u7cfb\u7edf\u884c\u4e3a\u7684\u5f71\u54cd\u3002\u800c\u76f8\u53cd\u5730\uff0c\u7f51\u7edc\u7814\u7a76\u4e3b\u8981\u5173\u6ce8\u7cfb\u7edf\u4e4b\u95f4\u901a\u4fe1\u884c\u4e3a\u7684\u7ec6\u8282\u3001\u5982\u4f55\u6539\u8fdb\u7279\u5b9a\u901a\u4fe1\u673a\u5236\u7684\u8868\u73b0\uff0c\u5e38\u5e38\u5ffd\u89c6\u4e86\u4e00\u4e2a\u4e8b\u5b9e\uff0c\u90a3\u5c31\u662f\u6539\u53d8\u5e94\u7528\u7a0b\u5e8f\u7684\u4e92\u52a8\u98ce\u683c\u6bd4\u6539\u53d8\u4e92\u52a8\u534f\u8bae\uff0c\u5bf9\u6574\u4f53\u8868\u73b0\u6709\u66f4\u5927\u7684\u5f71\u54cd\u3002\u6211\u8fd9\u7bc7\u6587\u7ae0\u7684\u5199\u4f5c\u76ee\u7684\uff0c\u5c31\u662f\u60f3\u5728\u7b26\u5408\u67b6\u6784\u539f\u7406\u7684\u524d\u63d0\u4e0b\uff0c\u7406\u89e3\u548c\u8bc4\u4f30\u4ee5\u7f51\u7edc\u4e3a\u57fa\u7840\u7684\u5e94\u7528\u8f6f\u4ef6\u7684\u67b6\u6784\u8bbe\u8ba1\uff0c\u5f97\u5230\u4e00\u4e2a\u529f\u80fd\u5f3a\u3001\u6027\u80fd\u597d\u3001\u9002\u5b9c\u901a\u4fe1\u7684\u67b6\u6784\u3002&#8221;<\/p>\n\n\n\n<p><strong>1.2\u3001\u540d\u79f0<\/strong><\/p>\n\n\n\n<p>Fielding\u5c06\u4ed6\u5bf9\u4e92\u8054\u7f51\u8f6f\u4ef6\u7684\u67b6\u6784\u539f\u5219\uff0c\u5b9a\u540d\u4e3aREST\uff0c\u5373Representational State Transfer\u7684\u7f29\u5199\u3002\u6211\u5bf9\u8fd9\u4e2a\u8bcd\u7ec4\u7684\u7ffb\u8bd1\u662f&#8221;\u8868\u73b0\u5c42\u72b6\u6001\u8f6c\u5316&#8221;\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u4e00\u4e2a\u67b6\u6784\u7b26\u5408REST\u539f\u5219\uff0c\u5c31\u79f0\u5b83\u4e3aRESTful\u67b6\u6784\u3002<\/p>\n\n\n\n<p>\u8981\u7406\u89e3RESTful\u67b6\u6784\uff0c\u6700\u597d\u7684\u65b9\u6cd5\u5c31\u662f\u53bb\u7406\u89e3Representational State Transfer\u8fd9\u4e2a\u8bcd\u7ec4\u5230\u5e95\u662f\u4ec0\u4e48\u610f\u601d\uff0c\u5b83\u7684\u6bcf\u4e00\u4e2a\u8bcd\u4ee3\u8868\u4e86\u4ec0\u4e48\u6db5\u4e49\u3002\u5982\u679c\u4f60\u628a\u8fd9\u4e2a\u540d\u79f0\u641e\u61c2\u4e86\uff0c\u4e5f\u5c31\u4e0d\u96be\u4f53\u4f1aREST\u662f\u4e00\u79cd\u4ec0\u4e48\u6837\u7684\u8bbe\u8ba1\u3002<\/p>\n\n\n\n<p><strong>1.3\u3001\u8d44\u6e90\uff08Resources\uff09<\/strong><\/p>\n\n\n\n<p>REST\u7684\u540d\u79f0&#8221;\u8868\u73b0\u5c42\u72b6\u6001\u8f6c\u5316&#8221;\u4e2d\uff0c\u7701\u7565\u4e86\u4e3b\u8bed\u3002&#8221;\u8868\u73b0\u5c42&#8221;\u5176\u5b9e\u6307\u7684\u662f&#8221;\u8d44\u6e90&#8221;\uff08Resources\uff09\u7684&#8221;\u8868\u73b0\u5c42&#8221;\u3002<\/p>\n\n\n\n<p>\u6240\u8c13&#8221;\u8d44\u6e90&#8221;\uff0c\u5c31\u662f\u7f51\u7edc\u4e0a\u7684\u4e00\u4e2a\u5b9e\u4f53\uff0c\u6216\u8005\u8bf4\u662f\u7f51\u7edc\u4e0a\u7684\u4e00\u4e2a\u5177\u4f53\u4fe1\u606f\u3002\u5b83\u53ef\u4ee5\u662f\u4e00\u6bb5\u6587\u672c\u3001\u4e00\u5f20\u56fe\u7247\u3001\u4e00\u9996\u6b4c\u66f2\u3001\u4e00\u79cd\u670d\u52a1\uff0c\u603b\u4e4b\u5c31\u662f\u4e00\u4e2a\u5177\u4f53\u7684\u5b9e\u5728\u3002\u4f60\u53ef\u4ee5\u7528\u4e00\u4e2aURI\uff08\u7edf\u4e00\u8d44\u6e90\u5b9a\u4f4d\u7b26\uff09\u6307\u5411\u5b83\uff0c\u6bcf\u79cd\u8d44\u6e90\u5bf9\u5e94\u4e00\u4e2a\u7279\u5b9a\u7684URI\u3002\u8981\u83b7\u53d6\u8fd9\u4e2a\u8d44\u6e90\uff0c\u8bbf\u95ee\u5b83\u7684URI\u5c31\u53ef\u4ee5\uff0c\u56e0\u6b64URI\u5c31\u6210\u4e86\u6bcf\u4e00\u4e2a\u8d44\u6e90\u7684\u5730\u5740\u6216\u72ec\u4e00\u65e0\u4e8c\u7684\u8bc6\u522b\u7b26\u3002<\/p>\n\n\n\n<p>\u6240\u8c13&#8221;\u4e0a\u7f51&#8221;\uff0c\u5c31\u662f\u4e0e\u4e92\u8054\u7f51\u4e0a\u4e00\u7cfb\u5217\u7684&#8221;\u8d44\u6e90&#8221;\u4e92\u52a8\uff0c\u8c03\u7528\u5b83\u7684URI\u3002<\/p>\n\n\n\n<p><strong>1.4\u3001\u8868\u73b0\u5c42\uff08Representation\uff09<\/strong><\/p>\n\n\n\n<p>&#8220;\u8d44\u6e90&#8221;\u662f\u4e00\u79cd\u4fe1\u606f\u5b9e\u4f53\uff0c\u5b83\u53ef\u4ee5\u6709\u591a\u79cd\u5916\u5728\u8868\u73b0\u5f62\u5f0f\u3002\u6211\u4eec\u628a&#8221;\u8d44\u6e90&#8221;\u5177\u4f53\u5448\u73b0\u51fa\u6765\u7684\u5f62\u5f0f\uff0c\u53eb\u505a\u5b83\u7684&#8221;\u8868\u73b0\u5c42&#8221;\uff08Representation\uff09\u3002<\/p>\n\n\n\n<p>\u6bd4\u5982\uff0c\u6587\u672c\u53ef\u4ee5\u7528txt\u683c\u5f0f\u8868\u73b0\uff0c\u4e5f\u53ef\u4ee5\u7528HTML\u683c\u5f0f\u3001XML\u683c\u5f0f\u3001JSON\u683c\u5f0f\u8868\u73b0\uff0c\u751a\u81f3\u53ef\u4ee5\u91c7\u7528\u4e8c\u8fdb\u5236\u683c\u5f0f\uff1b\u56fe\u7247\u53ef\u4ee5\u7528JPG\u683c\u5f0f\u8868\u73b0\uff0c\u4e5f\u53ef\u4ee5\u7528PNG\u683c\u5f0f\u8868\u73b0\u3002<\/p>\n\n\n\n<p>URI\u53ea\u4ee3\u8868\u8d44\u6e90\u7684\u5b9e\u4f53\uff0c\u4e0d\u4ee3\u8868\u5b83\u7684\u5f62\u5f0f\u3002\u4e25\u683c\u5730\u8bf4\uff0c\u6709\u4e9b\u7f51\u5740\u6700\u540e\u7684&#8221;.html&#8221;\u540e\u7f00\u540d\u662f\u4e0d\u5fc5\u8981\u7684\uff0c\u56e0\u4e3a\u8fd9\u4e2a\u540e\u7f00\u540d\u8868\u793a\u683c\u5f0f\uff0c\u5c5e\u4e8e&#8221;\u8868\u73b0\u5c42&#8221;\u8303\u7574\uff0c\u800cURI\u5e94\u8be5\u53ea\u4ee3\u8868&#8221;\u8d44\u6e90&#8221;\u7684\u4f4d\u7f6e\u3002\u5b83\u7684\u5177\u4f53\u8868\u73b0\u5f62\u5f0f\uff0c\u5e94\u8be5\u5728HTTP\u8bf7\u6c42\u7684\u5934\u4fe1\u606f\u4e2d\u7528Accept\u548cContent-Type\u5b57\u6bb5\u6307\u5b9a\uff0c\u8fd9\u4e24\u4e2a\u5b57\u6bb5\u624d\u662f\u5bf9&#8221;\u8868\u73b0\u5c42&#8221;\u7684\u63cf\u8ff0\u3002<\/p>\n\n\n\n<p><strong>1.5\u3001\u72b6\u6001\u8f6c\u5316\uff08State Transfer\uff09<\/strong><\/p>\n\n\n\n<p>\u8bbf\u95ee\u4e00\u4e2a\u7f51\u7ad9\uff0c\u5c31\u4ee3\u8868\u4e86\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u7684\u4e00\u4e2a\u4e92\u52a8\u8fc7\u7a0b\u3002\u5728\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\uff0c\u52bf\u5fc5\u6d89\u53ca\u5230\u6570\u636e\u548c\u72b6\u6001\u7684\u53d8\u5316\u3002<\/p>\n\n\n\n<p>\u4e92\u8054\u7f51\u901a\u4fe1\u534f\u8baeHTTP\u534f\u8bae\uff0c\u662f\u4e00\u4e2a\u65e0\u72b6\u6001\u534f\u8bae\u3002\u8fd9\u610f\u5473\u7740\uff0c\u6240\u6709\u7684\u72b6\u6001\u90fd\u4fdd\u5b58\u5728\u670d\u52a1\u5668\u7aef\u3002\u56e0\u6b64\uff0c\u5982\u679c\u5ba2\u6237\u7aef\u60f3\u8981\u64cd\u4f5c\u670d\u52a1\u5668\uff0c\u5fc5\u987b\u901a\u8fc7\u67d0\u79cd\u624b\u6bb5\uff0c\u8ba9\u670d\u52a1\u5668\u7aef\u53d1\u751f&#8221;\u72b6\u6001\u8f6c\u5316&#8221;\uff08State Transfer\uff09\u3002\u800c\u8fd9\u79cd\u8f6c\u5316\u662f\u5efa\u7acb\u5728\u8868\u73b0\u5c42\u4e4b\u4e0a\u7684\uff0c\u6240\u4ee5\u5c31\u662f&#8221;\u8868\u73b0\u5c42\u72b6\u6001\u8f6c\u5316&#8221;\u3002<\/p>\n\n\n\n<p>\u5ba2\u6237\u7aef\u7528\u5230\u7684\u624b\u6bb5\uff0c\u53ea\u80fd\u662fHTTP\u534f\u8bae\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u5c31\u662fHTTP\u534f\u8bae\u91cc\u9762\uff0c\u56db\u4e2a\u8868\u793a\u64cd\u4f5c\u65b9\u5f0f\u7684\u52a8\u8bcd\uff1aGET\u3001POST\u3001PUT\u3001DELETE\u3002\u5b83\u4eec\u5206\u522b\u5bf9\u5e94\u56db\u79cd\u57fa\u672c\u64cd\u4f5c\uff1aGET\u7528\u6765\u83b7\u53d6\u8d44\u6e90\uff0cPOST\u7528\u6765\u65b0\u5efa\u8d44\u6e90\uff08\u4e5f\u53ef\u4ee5\u7528\u4e8e\u66f4\u65b0\u8d44\u6e90\uff09\uff0cPUT\u7528\u6765\u66f4\u65b0\u8d44\u6e90\uff0cDELETE\u7528\u6765\u5220\u9664\u8d44\u6e90\u3002<\/p>\n\n\n\n<p><strong>1.6\u3001\u7efc\u8ff0<\/strong><\/p>\n\n\n\n<p>\u7efc\u5408\u4e0a\u9762\u7684\u89e3\u91ca\uff0c\u6211\u4eec\u603b\u7ed3\u4e00\u4e0b\u4ec0\u4e48\u662fRESTful\u67b6\u6784\uff1a<\/p>\n\n\n\n<ul><li>\u6bcf\u4e00\u4e2aURI\u4ee3\u8868\u4e00\u79cd\u8d44\u6e90\uff1b<\/li><li>\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u4e4b\u95f4\uff0c\u4f20\u9012\u8fd9\u79cd\u8d44\u6e90\u7684\u67d0\u79cd\u8868\u73b0\u5c42\uff1b<\/li><li>\u5ba2\u6237\u7aef\u901a\u8fc7\u56db\u4e2aHTTP\u52a8\u8bcd\uff0c\u5bf9\u670d\u52a1\u5668\u7aef\u8d44\u6e90\u8fdb\u884c\u64cd\u4f5c\uff0c\u5b9e\u73b0&#8221;\u8868\u73b0\u5c42\u72b6\u6001\u8f6c\u5316&#8221;\u3002<\/li><\/ul>\n\n\n\n<p><strong>1.7\u3001\u8bef\u533a<\/strong><\/p>\n\n\n\n<p>RESTful\u67b6\u6784\u6709\u4e00\u4e9b\u5178\u578b\u7684\u8bbe\u8ba1\u8bef\u533a\u3002<\/p>\n\n\n\n<p>\u6700\u5e38\u89c1\u7684\u4e00\u79cd\u8bbe\u8ba1\u9519\u8bef\uff0c\u5c31\u662fURI\u5305\u542b\u52a8\u8bcd\u3002\u56e0\u4e3a&#8221;\u8d44\u6e90&#8221;\u8868\u793a\u4e00\u79cd\u5b9e\u4f53\uff0c\u6240\u4ee5\u5e94\u8be5\u662f\u540d\u8bcd\uff0cURI\u4e0d\u5e94\u8be5\u6709\u52a8\u8bcd\uff0c\u52a8\u8bcd\u5e94\u8be5\u653e\u5728HTTP\u534f\u8bae\u4e2d\u3002<\/p>\n\n\n\n<p>\u4e3e\u4f8b\u6765\u8bf4\uff0c\u67d0\u4e2aURI\u662f\/posts\/show\/1\uff0c\u5176\u4e2dshow\u662f\u52a8\u8bcd\uff0c\u8fd9\u4e2aURI\u5c31\u8bbe\u8ba1\u9519\u4e86\uff0c\u6b63\u786e\u7684\u5199\u6cd5\u5e94\u8be5\u662f\/posts\/1\uff0c\u7136\u540e\u7528GET\u65b9\u6cd5\u8868\u793ashow\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u67d0\u4e9b\u52a8\u4f5c\u662fHTTP\u52a8\u8bcd\u8868\u793a\u4e0d\u4e86\u7684\uff0c\u4f60\u5c31\u5e94\u8be5\u628a\u52a8\u4f5c\u505a\u6210\u4e00\u79cd\u8d44\u6e90\u3002\u6bd4\u5982\u7f51\u4e0a\u6c47\u6b3e\uff0c\u4ece\u8d26\u62371\u5411\u8d26\u62372\u6c47\u6b3e500\u5143\uff0c\u9519\u8bef\u7684URI\u662f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">POST \/accounts\/1\/transfer\/500\/to\/2<\/pre>\n\n\n\n<p>\u6b63\u786e\u7684\u5199\u6cd5\u662f\u628a\u52a8\u8bcdtransfer\u6539\u6210\u540d\u8bcdtransaction\uff0c\u8d44\u6e90\u4e0d\u80fd\u662f\u52a8\u8bcd\uff0c\u4f46\u662f\u53ef\u4ee5\u662f\u4e00\u79cd\u670d\u52a1\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">POST \/transaction HTTP\/1.1\nHost: 127.0.0.1\nfrom=1&amp;to=2&amp;amount=500.00<\/pre>\n\n\n\n<p>\u53e6\u4e00\u4e2a\u8bbe\u8ba1\u8bef\u533a\uff0c\u5c31\u662f\u5728URI\u4e2d\u52a0\u5165\u7248\u672c\u53f7\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">http:\/\/www.example.com\/app\/1.0\/foo\nhttp:\/\/www.example.com\/app\/1.1\/foo\nhttp:\/\/www.example.com\/app\/2.0\/foo<\/pre>\n\n\n\n<p>\u56e0\u4e3a\u4e0d\u540c\u7684\u7248\u672c\uff0c\u53ef\u4ee5\u7406\u89e3\u6210\u540c\u4e00\u79cd\u8d44\u6e90\u7684\u4e0d\u540c\u8868\u73b0\u5f62\u5f0f\uff0c\u6240\u4ee5\u5e94\u8be5\u91c7\u7528\u540c\u4e00\u4e2aURI\u3002\u7248\u672c\u53f7\u53ef\u4ee5\u5728HTTP\u8bf7\u6c42\u5934\u4fe1\u606f\u7684Accept\u5b57\u6bb5\u4e2d\u8fdb\u884c\u533a\u5206\uff08\u53c2\u89c1Versioning REST Services\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Accept: vnd.example-com.foo+json; version=1.0\nAccept: vnd.example-com.foo+json; version=1.1\nAccept: vnd.example-com.foo+json; version=2.0<\/pre>\n\n\n\n<p><strong>\u4e8c\u3001RESTful API \u8bbe\u8ba1\u6307\u5357<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u7f51\u7edc\u5e94\u7528\u7a0b\u5e8f\uff0c\u5206\u4e3a\u524d\u7aef\u548c\u540e\u7aef\u4e24\u4e2a\u90e8\u5206\u3002\u5f53\u524d\u7684\u53d1\u5c55\u8d8b\u52bf\uff0c\u5c31\u662f\u524d\u7aef\u8bbe\u5907\u5c42\u51fa\u4e0d\u7a77\uff08\u624b\u673a\u3001\u5e73\u677f\u3001\u684c\u9762\u7535\u8111\u3001\u5176\u4ed6\u4e13\u7528\u8bbe\u5907&#8230;&#8230;\uff09\u3002<\/p>\n\n\n\n<p>\u56e0\u6b64\uff0c\u5fc5\u987b\u6709\u4e00\u79cd\u7edf\u4e00\u7684\u673a\u5236\uff0c\u65b9\u4fbf\u4e0d\u540c\u7684\u524d\u7aef\u8bbe\u5907\u4e0e\u540e\u7aef\u8fdb\u884c\u901a\u4fe1\u3002\u8fd9\u5bfc\u81f4API\u6784\u67b6\u7684\u6d41\u884c\uff0c\u751a\u81f3\u51fa\u73b0&#8221;API First&#8221;\u7684\u8bbe\u8ba1\u601d\u60f3\u3002RESTful API\u662f\u76ee\u524d\u6bd4\u8f83\u6210\u719f\u7684\u4e00\u5957\u4e92\u8054\u7f51\u5e94\u7528\u7a0b\u5e8f\u7684API\u8bbe\u8ba1\u7406\u8bba\u3002\u6211\u4ee5\u524d\u5199\u8fc7\u4e00\u7bc7\u300a\u7406\u89e3RESTful\u67b6\u6784\u300b\uff0c\u63a2\u8ba8\u5982\u4f55\u7406\u89e3\u8fd9\u4e2a\u6982\u5ff5\u3002<\/p>\n\n\n\n<p>\u4eca\u5929\uff0c\u6211\u5c06\u4ecb\u7ecdRESTful API\u7684\u8bbe\u8ba1\u7ec6\u8282\uff0c\u63a2\u8ba8\u5982\u4f55\u8bbe\u8ba1\u4e00\u5957\u5408\u7406\u3001\u597d\u7528\u7684API\u3002<\/p>\n\n\n\n<p id=\"jumpto_1_7\"><strong>2.1\u3001\u534f\u8bae<\/strong><\/p>\n\n\n\n<p>API\u4e0e\u7528\u6237\u7684\u901a\u4fe1\u534f\u8bae\uff0c\u603b\u662f\u4f7f\u7528HTTPs\u534f\u8bae\u3002<\/p>\n\n\n\n<p id=\"jumpto_1_8\"><strong>2.2\u3001\u57df\u540d<\/strong><\/p>\n\n\n\n<p>\u5e94\u8be5\u5c3d\u91cf\u5c06API\u90e8\u7f72\u5728\u4e13\u7528\u57df\u540d\u4e4b\u4e0b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">https:\/\/api.example.com<\/pre>\n\n\n\n<p>\u5982\u679c\u786e\u5b9aAPI\u5f88\u7b80\u5355\uff0c\u4e0d\u4f1a\u6709\u8fdb\u4e00\u6b65\u6269\u5c55\uff0c\u53ef\u4ee5\u8003\u8651\u653e\u5728\u4e3b\u57df\u540d\u4e0b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">https:\/\/example.org\/api\/<\/pre>\n\n\n\n<p><strong>2.3\u3001\u7248\u672c\uff08Versioning\uff09<\/strong><\/p>\n\n\n\n<p>\u5e94\u8be5\u5c06API\u7684\u7248\u672c\u53f7\u653e\u5165URL\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">https:\/\/api.example.com\/v1\/<\/pre>\n\n\n\n<p>\u53e6\u4e00\u79cd\u505a\u6cd5\u662f\uff0c\u5c06\u7248\u672c\u53f7\u653e\u5728HTTP\u5934\u4fe1\u606f\u4e2d\uff0c\u4f46\u4e0d\u5982\u653e\u5165URL\u65b9\u4fbf\u548c\u76f4\u89c2\u3002Github\u91c7\u7528\u8fd9\u79cd\u505a\u6cd5\u3002<\/p>\n\n\n\n<p><strong>2.4\u3001\u8def\u5f84\uff08Endpoint\uff09<\/strong><\/p>\n\n\n\n<p>\u8def\u5f84\u53c8\u79f0&#8221;\u7ec8\u70b9&#8221;\uff08endpoint\uff09\uff0c\u8868\u793aAPI\u7684\u5177\u4f53\u7f51\u5740\u3002<\/p>\n\n\n\n<p>\u5728RESTful\u67b6\u6784\u4e2d\uff0c\u6bcf\u4e2a\u7f51\u5740\u4ee3\u8868\u4e00\u79cd\u8d44\u6e90\uff08resource\uff09\uff0c\u6240\u4ee5\u7f51\u5740\u4e2d\u4e0d\u80fd\u6709\u52a8\u8bcd\uff0c\u53ea\u80fd\u6709\u540d\u8bcd\uff0c\u800c\u4e14\u6240\u7528\u7684\u540d\u8bcd\u5f80\u5f80\u4e0e\u6570\u636e\u5e93\u7684\u8868\u683c\u540d\u5bf9\u5e94\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u6570\u636e\u5e93\u4e2d\u7684\u8868\u90fd\u662f\u540c\u79cd\u8bb0\u5f55\u7684&#8221;\u96c6\u5408&#8221;\uff08collection\uff09\uff0c\u6240\u4ee5API\u4e2d\u7684\u540d\u8bcd\u4e5f\u5e94\u8be5\u4f7f\u7528\u590d\u6570\u3002<\/p>\n\n\n\n<p>\u4e3e\u4f8b\u6765\u8bf4\uff0c\u6709\u4e00\u4e2aAPI\u63d0\u4f9b\u52a8\u7269\u56ed\uff08zoo\uff09\u7684\u4fe1\u606f\uff0c\u8fd8\u5305\u62ec\u5404\u79cd\u52a8\u7269\u548c\u96c7\u5458\u7684\u4fe1\u606f\uff0c\u5219\u5b83\u7684\u8def\u5f84\u5e94\u8be5\u8bbe\u8ba1\u6210\u4e0b\u9762\u8fd9\u6837\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">https:\/\/api.example.com\/v1\/zoos\nhttps:\/\/api.example.com\/v1\/animals\nhttps:\/\/api.example.com\/v1\/employees<\/pre>\n\n\n\n<p><strong>2.5\u3001HTTP\u52a8\u8bcd<\/strong><\/p>\n\n\n\n<p>\u5bf9\u4e8e\u8d44\u6e90\u7684\u5177\u4f53\u64cd\u4f5c\u7c7b\u578b\uff0c\u7531HTTP\u52a8\u8bcd\u8868\u793a\u3002<\/p>\n\n\n\n<p>\u5e38\u7528\u7684HTTP\u52a8\u8bcd\u6709\u4e0b\u9762\u4e94\u4e2a\uff08\u62ec\u53f7\u91cc\u662f\u5bf9\u5e94\u7684SQL\u547d\u4ee4\uff09\u3002<\/p>\n\n\n\n<ul><li>GET\uff08SELECT\uff09\uff1a\u4ece\u670d\u52a1\u5668\u53d6\u51fa\u8d44\u6e90\uff08\u4e00\u9879\u6216\u591a\u9879\uff09\u3002<\/li><li>POST\uff08CREATE\uff09\uff1a\u5728\u670d\u52a1\u5668\u65b0\u5efa\u4e00\u4e2a\u8d44\u6e90\u3002<\/li><li>PUT\uff08UPDATE\uff09\uff1a\u5728\u670d\u52a1\u5668\u66f4\u65b0\u8d44\u6e90\uff08\u5ba2\u6237\u7aef\u63d0\u4f9b\u6539\u53d8\u540e\u7684\u5b8c\u6574\u8d44\u6e90\uff09\u3002<\/li><li>PATCH\uff08UPDATE\uff09\uff1a\u5728\u670d\u52a1\u5668\u66f4\u65b0\u8d44\u6e90\uff08\u5ba2\u6237\u7aef\u63d0\u4f9b\u6539\u53d8\u7684\u5c5e\u6027\uff09\u3002<\/li><li>DELETE\uff08DELETE\uff09\uff1a\u4ece\u670d\u52a1\u5668\u5220\u9664\u8d44\u6e90\u3002<\/li><\/ul>\n\n\n\n<p>\u8fd8\u6709\u4e24\u4e2a\u4e0d\u5e38\u7528\u7684HTTP\u52a8\u8bcd\u3002<\/p>\n\n\n\n<ul><li>HEAD\uff1a\u83b7\u53d6\u8d44\u6e90\u7684\u5143\u6570\u636e\u3002<\/li><li>OPTIONS\uff1a\u83b7\u53d6\u4fe1\u606f\uff0c\u5173\u4e8e\u8d44\u6e90\u7684\u54ea\u4e9b\u5c5e\u6027\u662f\u5ba2\u6237\u7aef\u53ef\u4ee5\u6539\u53d8\u7684\u3002<\/li><\/ul>\n\n\n\n<p>\u4e0b\u9762\u662f\u4e00\u4e9b\u4f8b\u5b50\u3002<\/p>\n\n\n\n<ul><li>GET \/zoos\uff1a\u5217\u51fa\u6240\u6709\u52a8\u7269\u56ed<\/li><li>POST \/zoos\uff1a\u65b0\u5efa\u4e00\u4e2a\u52a8\u7269\u56ed<\/li><li>GET \/zoos\/ID\uff1a\u83b7\u53d6\u67d0\u4e2a\u6307\u5b9a\u52a8\u7269\u56ed\u7684\u4fe1\u606f<\/li><li>PUT \/zoos\/ID\uff1a\u66f4\u65b0\u67d0\u4e2a\u6307\u5b9a\u52a8\u7269\u56ed\u7684\u4fe1\u606f\uff08\u63d0\u4f9b\u8be5\u52a8\u7269\u56ed\u7684\u5168\u90e8\u4fe1\u606f\uff09<\/li><li>PATCH \/zoos\/ID\uff1a\u66f4\u65b0\u67d0\u4e2a\u6307\u5b9a\u52a8\u7269\u56ed\u7684\u4fe1\u606f\uff08\u63d0\u4f9b\u8be5\u52a8\u7269\u56ed\u7684\u90e8\u5206\u4fe1\u606f\uff09<\/li><li>DELETE \/zoos\/ID\uff1a\u5220\u9664\u67d0\u4e2a\u52a8\u7269\u56ed<\/li><li>GET \/zoos\/ID\/animals\uff1a\u5217\u51fa\u67d0\u4e2a\u6307\u5b9a\u52a8\u7269\u56ed\u7684\u6240\u6709\u52a8\u7269<\/li><li>DELETE \/zoos\/ID\/animals\/ID\uff1a\u5220\u9664\u67d0\u4e2a\u6307\u5b9a\u52a8\u7269\u56ed\u7684\u6307\u5b9a\u52a8\u7269<\/li><\/ul>\n\n\n\n<p><strong>2.6\u3001\u8fc7\u6ee4\u4fe1\u606f\uff08Filtering\uff09<\/strong><\/p>\n\n\n\n<p>\u5982\u679c\u8bb0\u5f55\u6570\u91cf\u5f88\u591a\uff0c\u670d\u52a1\u5668\u4e0d\u53ef\u80fd\u90fd\u5c06\u5b83\u4eec\u8fd4\u56de\u7ed9\u7528\u6237\u3002API\u5e94\u8be5\u63d0\u4f9b\u53c2\u6570\uff0c\u8fc7\u6ee4\u8fd4\u56de\u7ed3\u679c\u3002<\/p>\n\n\n\n<p>\u4e0b\u9762\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u53c2\u6570\u3002<\/p>\n\n\n\n<ul><li>?limit=10\uff1a\u6307\u5b9a\u8fd4\u56de\u8bb0\u5f55\u7684\u6570\u91cf<\/li><li>?offset=10\uff1a\u6307\u5b9a\u8fd4\u56de\u8bb0\u5f55\u7684\u5f00\u59cb\u4f4d\u7f6e\u3002<\/li><li>?page=2&amp;per_page=100\uff1a\u6307\u5b9a\u7b2c\u51e0\u9875\uff0c\u4ee5\u53ca\u6bcf\u9875\u7684\u8bb0\u5f55\u6570\u3002<\/li><li>?sortby=name&amp;order=asc\uff1a\u6307\u5b9a\u8fd4\u56de\u7ed3\u679c\u6309\u7167\u54ea\u4e2a\u5c5e\u6027\u6392\u5e8f\uff0c\u4ee5\u53ca\u6392\u5e8f\u987a\u5e8f\u3002<\/li><li>?animal_type_id=1\uff1a\u6307\u5b9a\u7b5b\u9009\u6761\u4ef6<\/li><\/ul>\n\n\n\n<p>\u53c2\u6570\u7684\u8bbe\u8ba1\u5141\u8bb8\u5b58\u5728\u5197\u4f59\uff0c\u5373\u5141\u8bb8API\u8def\u5f84\u548cURL\u53c2\u6570\u5076\u5c14\u6709\u91cd\u590d\u3002\u6bd4\u5982\uff0cGET \/zoo\/ID\/animals \u4e0e GET \/animals?zoo_id=ID \u7684\u542b\u4e49\u662f\u76f8\u540c\u7684\u3002<\/p>\n\n\n\n<p><strong>2.7\u3001\u72b6\u6001\u7801\uff08Status Codes\uff09<\/strong><\/p>\n\n\n\n<p>\u670d\u52a1\u5668\u5411\u7528\u6237\u8fd4\u56de\u7684\u72b6\u6001\u7801\u548c\u63d0\u793a\u4fe1\u606f\uff0c\u5e38\u89c1\u7684\u6709\u4ee5\u4e0b\u4e00\u4e9b\uff08\u65b9\u62ec\u53f7\u4e2d\u662f\u8be5\u72b6\u6001\u7801\u5bf9\u5e94\u7684HTTP\u52a8\u8bcd\uff09\u3002<\/p>\n\n\n\n<ul><li>200 OK &#8211; [GET]\uff1a\u670d\u52a1\u5668\u6210\u529f\u8fd4\u56de\u7528\u6237\u8bf7\u6c42\u7684\u6570\u636e\uff0c\u8be5\u64cd\u4f5c\u662f\u5e42\u7b49\u7684\uff08Idempotent\uff09\u3002<\/li><li>201 CREATED &#8211; [POST\/PUT\/PATCH]\uff1a\u7528\u6237\u65b0\u5efa\u6216\u4fee\u6539\u6570\u636e\u6210\u529f\u3002<\/li><li>202 Accepted &#8211; [*]\uff1a\u8868\u793a\u4e00\u4e2a\u8bf7\u6c42\u5df2\u7ecf\u8fdb\u5165\u540e\u53f0\u6392\u961f\uff08\u5f02\u6b65\u4efb\u52a1\uff09<\/li><li>204 NO CONTENT &#8211; [DELETE]\uff1a\u7528\u6237\u5220\u9664\u6570\u636e\u6210\u529f\u3002<\/li><li>400 INVALID REQUEST &#8211; [POST\/PUT\/PATCH]\uff1a\u7528\u6237\u53d1\u51fa\u7684\u8bf7\u6c42\u6709\u9519\u8bef\uff0c\u670d\u52a1\u5668\u6ca1\u6709\u8fdb\u884c\u65b0\u5efa\u6216\u4fee\u6539\u6570\u636e\u7684\u64cd\u4f5c\uff0c\u8be5\u64cd\u4f5c\u662f\u5e42\u7b49\u7684\u3002<\/li><li>401 Unauthorized &#8211; [*]\uff1a\u8868\u793a\u7528\u6237\u6ca1\u6709\u6743\u9650\uff08\u4ee4\u724c\u3001\u7528\u6237\u540d\u3001\u5bc6\u7801\u9519\u8bef\uff09\u3002<\/li><li>403 Forbidden &#8211; [*] \u8868\u793a\u7528\u6237\u5f97\u5230\u6388\u6743\uff08\u4e0e401\u9519\u8bef\u76f8\u5bf9\uff09\uff0c\u4f46\u662f\u8bbf\u95ee\u662f\u88ab\u7981\u6b62\u7684\u3002<\/li><li>404 NOT FOUND &#8211; [*]\uff1a\u7528\u6237\u53d1\u51fa\u7684\u8bf7\u6c42\u9488\u5bf9\u7684\u662f\u4e0d\u5b58\u5728\u7684\u8bb0\u5f55\uff0c\u670d\u52a1\u5668\u6ca1\u6709\u8fdb\u884c\u64cd\u4f5c\uff0c\u8be5\u64cd\u4f5c\u662f\u5e42\u7b49\u7684\u3002<\/li><li>406 Not Acceptable &#8211; [GET]\uff1a\u7528\u6237\u8bf7\u6c42\u7684\u683c\u5f0f\u4e0d\u53ef\u5f97\uff08\u6bd4\u5982\u7528\u6237\u8bf7\u6c42JSON\u683c\u5f0f\uff0c\u4f46\u662f\u53ea\u6709XML\u683c\u5f0f\uff09\u3002<\/li><li>410 Gone -[GET]\uff1a\u7528\u6237\u8bf7\u6c42\u7684\u8d44\u6e90\u88ab\u6c38\u4e45\u5220\u9664\uff0c\u4e14\u4e0d\u4f1a\u518d\u5f97\u5230\u7684\u3002<\/li><li>422 Unprocesable entity &#8211; [POST\/PUT\/PATCH] \u5f53\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\u65f6\uff0c\u53d1\u751f\u4e00\u4e2a\u9a8c\u8bc1\u9519\u8bef\u3002<\/li><li>500 INTERNAL SERVER ERROR &#8211; [*]\uff1a\u670d\u52a1\u5668\u53d1\u751f\u9519\u8bef\uff0c\u7528\u6237\u5c06\u65e0\u6cd5\u5224\u65ad\u53d1\u51fa\u7684\u8bf7\u6c42\u662f\u5426\u6210\u529f\u3002<\/li><\/ul>\n\n\n\n<p><strong>2.8\u3001\u9519\u8bef\u5904\u7406\uff08Error handling\uff09<\/strong><\/p>\n\n\n\n<p>\u5982\u679c\u72b6\u6001\u7801\u662f4xx\uff0c\u5c31\u5e94\u8be5\u5411\u7528\u6237\u8fd4\u56de\u51fa\u9519\u4fe1\u606f\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u8fd4\u56de\u7684\u4fe1\u606f\u4e2d\u5c06error\u4f5c\u4e3a\u952e\u540d\uff0c\u51fa\u9519\u4fe1\u606f\u4f5c\u4e3a\u952e\u503c\u5373\u53ef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{\n    error: \"Invalid API key\"\n}\n<\/pre>\n\n\n\n<p><strong>2.9\u3001\u8fd4\u56de\u7ed3\u679c<\/strong><\/p>\n\n\n\n<p>\u9488\u5bf9\u4e0d\u540c\u64cd\u4f5c\uff0c\u670d\u52a1\u5668\u5411\u7528\u6237\u8fd4\u56de\u7684\u7ed3\u679c\u5e94\u8be5\u7b26\u5408\u4ee5\u4e0b\u89c4\u8303\u3002<\/p>\n\n\n\n<ul><li>GET \/collection\uff1a\u8fd4\u56de\u8d44\u6e90\u5bf9\u8c61\u7684\u5217\u8868\uff08\u6570\u7ec4\uff09<\/li><li>GET \/collection\/resource\uff1a\u8fd4\u56de\u5355\u4e2a\u8d44\u6e90\u5bf9\u8c61<\/li><li>POST \/collection\uff1a\u8fd4\u56de\u65b0\u751f\u6210\u7684\u8d44\u6e90\u5bf9\u8c61<\/li><li>PUT \/collection\/resource\uff1a\u8fd4\u56de\u5b8c\u6574\u7684\u8d44\u6e90\u5bf9\u8c61<\/li><li>PATCH \/collection\/resource\uff1a\u8fd4\u56de\u5b8c\u6574\u7684\u8d44\u6e90\u5bf9\u8c61<\/li><li>DELETE \/collection\/resource\uff1a\u8fd4\u56de\u4e00\u4e2a\u7a7a\u6587\u6863<\/li><\/ul>\n\n\n\n<p><strong>2.10\u3001Hypermedia API<\/strong><\/p>\n\n\n\n<p>RESTful API\u6700\u597d\u505a\u5230Hypermedia\uff0c\u5373\u8fd4\u56de\u7ed3\u679c\u4e2d\u63d0\u4f9b\u94fe\u63a5\uff0c\u8fde\u5411\u5176\u4ed6API\u65b9\u6cd5\uff0c\u4f7f\u5f97\u7528\u6237\u4e0d\u67e5\u6587\u6863\uff0c\u4e5f\u77e5\u9053\u4e0b\u4e00\u6b65\u5e94\u8be5\u505a\u4ec0\u4e48\u3002<\/p>\n\n\n\n<p>\u6bd4\u5982\uff0c\u5f53\u7528\u6237\u5411api.example.com\u7684\u6839\u76ee\u5f55\u53d1\u51fa\u8bf7\u6c42\uff0c\u4f1a\u5f97\u5230\u8fd9\u6837\u4e00\u4e2a\u6587\u6863\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\"link\": {\n  \"rel\":   \"collection https:\/\/www.example.com\/zoos\",\n  \"href\":  \"https:\/\/api.example.com\/zoos\",\n  \"title\": \"List of zoos\",\n  \"type\":  \"application\/vnd.yourformat+json\"\n}}<\/pre>\n\n\n\n<p>\u4e0a\u9762\u4ee3\u7801\u8868\u793a\uff0c\u6587\u6863\u4e2d\u6709\u4e00\u4e2alink\u5c5e\u6027\uff0c\u7528\u6237\u8bfb\u53d6\u8fd9\u4e2a\u5c5e\u6027\u5c31\u77e5\u9053\u4e0b\u4e00\u6b65\u8be5\u8c03\u7528\u4ec0\u4e48API\u4e86\u3002rel\u8868\u793a\u8fd9\u4e2aAPI\u4e0e\u5f53\u524d\u7f51\u5740\u7684\u5173\u7cfb\uff08collection\u5173\u7cfb\uff0c\u5e76\u7ed9\u51fa\u8be5collection\u7684\u7f51\u5740\uff09\uff0chref\u8868\u793aAPI\u7684\u8def\u5f84\uff0ctitle\u8868\u793aAPI\u7684\u6807\u9898\uff0ctype\u8868\u793a\u8fd4\u56de\u7c7b\u578b\u3002<\/p>\n\n\n\n<p>Hypermedia API\u7684\u8bbe\u8ba1\u88ab\u79f0\u4e3aHATEOAS\u3002Github\u7684API\u5c31\u662f\u8fd9\u79cd\u8bbe\u8ba1\uff0c\u8bbf\u95eeapi.github.com\u4f1a\u5f97\u5230\u4e00\u4e2a\u6240\u6709\u53ef\u7528API\u7684\u7f51\u5740\u5217\u8868\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\n  \"current_user_url\": \"https:\/\/api.github.com\/user\",\n  \"authorizations_url\": \"https:\/\/api.github.com\/authorizations\",\n  \/\/ ...\n}<\/pre>\n\n\n\n<p>\u4ece\u4e0a\u9762\u53ef\u4ee5\u770b\u5230\uff0c\u5982\u679c\u60f3\u83b7\u53d6\u5f53\u524d\u7528\u6237\u7684\u4fe1\u606f\uff0c\u5e94\u8be5\u53bb\u8bbf\u95eeapi.github.com\/user\uff0c\u7136\u540e\u5c31\u5f97\u5230\u4e86\u4e0b\u9762\u7ed3\u679c\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\n  \"message\": \"Requires authentication\",\n  \"documentation_url\": \"https:\/\/developer.github.com\/v3\"\n}<\/pre>\n\n\n\n<p>\u4e0a\u9762\u4ee3\u7801\u8868\u793a\uff0c\u670d\u52a1\u5668\u7ed9\u51fa\u4e86\u63d0\u793a\u4fe1\u606f\uff0c\u4ee5\u53ca\u6587\u6863\u7684\u7f51\u5740\u3002<\/p>\n\n\n\n<p><strong>2.11\u3001\u5176\u4ed6<\/strong><\/p>\n\n\n\n<ul><li>API\u7684\u8eab\u4efd\u8ba4\u8bc1\u5e94\u8be5\u4f7f\u7528OAuth 2.0\u6846\u67b6\u3002<\/li><li>\u670d\u52a1\u5668\u8fd4\u56de\u7684\u6570\u636e\u683c\u5f0f\uff0c\u5e94\u8be5\u5c3d\u91cf\u4f7f\u7528JSON\uff0c\u907f\u514d\u4f7f\u7528XML\u3002<\/li><\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u7406\u89e3RESTful\u67b6\u6784 \u8d8a\u6765\u8d8a\u591a\u7684\u4eba\u5f00\u59cb\u610f\u8bc6\u5230\uff0c\u7f51\u7ad9\u5373\u8f6f\u4ef6\uff0c\u800c\u4e14\u662f\u4e00\u79cd\u65b0\u578b\u7684\u8f6f\u4ef6\u3002 \u8fd9\u79cd&#8221;\u4e92\u8054 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/10529"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10529"}],"version-history":[{"count":4,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/10529\/revisions"}],"predecessor-version":[{"id":10533,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/10529\/revisions\/10533"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}