{"id":1013,"date":"2014-08-22T21:43:12","date_gmt":"2014-08-22T13:43:12","guid":{"rendered":"http:\/\/coderbee.net\/?p=1013"},"modified":"2014-08-22T21:46:51","modified_gmt":"2014-08-22T13:46:51","slug":"%e5%85%b3%e4%ba%8e-restful-%e7%9a%84%e4%b8%80%e7%82%b9%e6%80%9d%e8%80%83","status":"publish","type":"post","link":"https:\/\/coderbee.net\/index.php\/web\/20140822\/1013","title":{"rendered":"\u5173\u4e8e RESTful \u7684\u4e00\u70b9\u601d\u8003"},"content":{"rendered":"<h3>RESTful  \u662f\u4ec0\u4e48\uff1f<\/h3>\n<p>\u6765\u81ea\u300aSpring \u5b9e\u6218\u300b\uff1a<\/p>\n<p>REST \u7ec4\u6210\uff1a\u8868\u8ff0\u6027\u3001\u72b6\u6001\u3001\u8f6c\u79fb\u3002<\/p>\n<p>REST \u662f\u5c06\u8d44\u6e90\u7684\u72b6\u6001\u4ee5\u6700\u5408\u9002\u7684\u5f62\u5f0f\u4ece\u670d\u52a1\u5668\u8f6c\u79fb\u5230\u5ba2\u6237\u7aef\u3002<\/p>\n<h4>RESTless<\/h4>\n<p>RESTless \u662f\u9762\u5411\u884c\u4e3a\u7684\uff0c\u800c\u4e0d\u662f\u9762\u5411\u8d44\u6e90\u7684\u3002\u6bd4\u5982\uff1a<br \/>\n<code>http:\/\/host:port\/servletContext\/showUser.action?id=123<\/code><\/p>\n<p>\u5728\u8fd9\u4e2a URL \u91cc\uff0c<code>servletContext<\/code> \u662f servlet \u4e0a\u4e0b\u6587\u8def\u5f84\uff1b<code>showUser.action<\/code> \u662f\u63a7\u5236\u5668 URL \u6a21\u5f0f\uff0c\u5176\u4e2d <code>show<\/code> \u662f\u52a8\u8bcd\uff0c\u662f\u4e00\u79cd\u884c\u4e3a\uff1b<code>id=123<\/code> \u662f\u6807\u8bc6\u7b26\u3002<\/p>\n<h4>RESTful URL<\/h4>\n<p>\u6bd4\u5982\uff1a<code>http:\/\/host:port\/servletContext\/users\/123<\/code><\/p>\n<p>\u5728\u8fd9\u4e2a URL \u91cc\uff0c<code>users<\/code> \u662f\u8d44\u6e90\u7c7b\u578b\uff08\u540d\u8bcd\uff09\uff0c<code>123<\/code> \u662f\u7279\u5b9a\u7684 user\u3002<\/p>\n<p>\u8fd9\u4e2a URL \u5e76\u4e0d\u505a\u4efb\u4f55\u4e8b\u60c5\uff0c\u53ea\u662f\u6807\u8bc6\u4e86\u4e00\u4e2a\u8d44\u6e90\uff0c\u800c\u5bf9\u8fd9\u4e2a\u8d44\u6e90\u505a\u4ec0\u4e48\u662f\u7531 HTTP \u8bf7\u6c42\u7684\u65b9\u6cd5\u51b3\u5b9a\u7684\u3002<\/p>\n<p>RESTful URL \u7684\u4e00\u4e9b\u7279\u6027\uff1a<\/p>\n<ul>\n<li>\u4e0d\u4ec5\u5b9a\u4f4d\u8d44\u6e90\uff0c\u8fd8\u53ef\u4ee5\u552f\u4e00\u6807\u8bc6\u8fd9\u4e2a\u8d44\u6e90\uff1b<\/li>\n<li>\u6709\u5c42\u6b21\uff0c\u4ece\u5de6\u5230\u53f3\u8bfb\u65f6\uff0c\u662f\u4e00\u4e2a\u4ece\u62bd\u8c61\u5230\u5177\u4f53\u7684\u8fc7\u7a0b\uff1b<\/li>\n<li>\u5bf9\u4e8e\u670d\u52a1\u5668\u7aef\u5e94\u7528\uff0c\u8def\u5f84\u662f\u53c2\u6570\u5316\u7684\u3002<\/li>\n<\/ul>\n<p><!--more--><\/p>\n<table>\n<thead>\n<tr>\n<td>\u65b9\u6cd5<\/td>\n<td>\u63cf\u8ff0<\/td>\n<td>\u662f\u5426\u5b89\u5168<\/td>\n<td>\u662f\u5426\u5e42\u7b49<\/td>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>GET<\/td>\n<td>\u4ece\u670d\u52a1\u5668\u68c0\u7d22\u8d44\u6e90\u6570\u636e\u3002\u8d44\u6e90\u901a\u8fc7\u8bf7\u6c42\u7684 URL \u6765\u8fdb\u884c\u6807\u8bc6<\/td>\n<td>\u662f<\/td>\n<td>\u662f<\/td>\n<\/tr>\n<tr>\n<td>POST<\/td>\n<td>\u4f20\u9001\u6570\u636e\u5230\u670d\u52a1\u5668\u4e0a\uff0c\u6570\u636e\u4f1a\u7531\u76d1\u542c\u8be5\u8bf7\u6c42\u7684 URL \u7684\u5904\u7406\u5668\u6765\u8fdb\u884c\u5904\u7406<\/td>\n<td>\u5426<\/td>\n<td>\u5426<\/td>\n<\/tr>\n<tr>\n<td>PUT<\/td>\n<td>\u6309\u7167\u8bf7\u6c42\u7684 URL\uff0c\u653e\u7f6e\u8d44\u6e90\u6570\u636e\u5230\u670d\u52a1\u5668\u4e0a<\/td>\n<td>\u5426<\/td>\n<td>\u662f<\/td>\n<\/tr>\n<tr>\n<td>DELETE<\/td>\n<td>\u5c06\u8bf7\u6c42 URL \u6807\u8bc6\u7684\u8d44\u6e90\u4ece\u670d\u52a1\u5668\u4e0a\u5220\u9664<\/td>\n<td>\u5426<\/td>\n<td>\u662f<\/td>\n<\/tr>\n<tr>\n<td>OPTIONS<\/td>\n<td>\u8bf7\u6c42\u4e0e\u670d\u52a1\u5668\u901a\u4fe1\u53ef\u7528\u7684\u9009\u9879<\/td>\n<td>\u662f<\/td>\n<td>\u662f<\/td>\n<\/tr>\n<tr>\n<td>HEAD<\/td>\n<td>\u7c7b\u4f3c\u4e8e GET\uff0c\u4f46\u53ea\u4f1a\u8fd4\u56de\u5934\u90e8\u4fe1\u606f&#8211;\u5728\u54cd\u5e94\u4f53\u4e2d\u4e0d\u5e94\u8be5\u5305\u542b\u5185\u5bb9<\/td>\n<td>\u662f<\/td>\n<td>\u662f<\/td>\n<\/tr>\n<tr>\n<td>TRACE<\/td>\n<td>\u5c06\u8bf7\u6c42\u4f53\u7684\u5185\u5bb9\u8fd4\u56de\u7ed9\u5ba2\u6237<\/td>\n<td>\u662f<\/td>\n<td>\u662f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u4f01\u4e1a\u5e94\u7528\u662f\u5426\u9002\u5408\u7528 RESTful \uff1f<\/h3>\n<p>RESTful \u76ee\u524d\u7ed9\u6211\u7684\u5370\u8c61\u662f\uff0c\u9664\u4e86\u8ba9 URL \u66f4\u5177\u8868\u8ff0\u6027\u5916\uff0c\u6ca1\u6709\u5176\u4ed6\u592a\u591a\u597d\u5904\u3002<\/p>\n<p>\u4f46\u662f URL \u53c2\u6570\u5316\u5e26\u6765\u7684\u4e00\u4e2a\u4e3b\u8981\u95ee\u9898\u662f\uff1a\u8bbf\u95ee\u65e5\u5fd7\u7684\u5206\u6790\u3001\u7edf\u8ba1\u5f88\u56f0\u96be\u3002\u5c31\u7b97\u662f\u8bbf\u95ee\u540c\u4e00\u4e2a API \u63a7\u5236\u5668\uff0c\u7531\u4e8e\u53c2\u6570\u503c\u4e0d\u540c\uff0c\u5bfc\u81f4\u8bbf\u95ee\u4e0d\u540c\u8d44\u6e90\u7684 URL \u662f\u4e0d\u4e00\u6837\u7684\uff0c\u60f3\u901a\u8fc7\u5206\u6790\u8bbf\u95ee\u65e5\u5fd7\u6765\u67e5\u770b\u6bcf\u4e2a API \u7684\u8c03\u7528\u60c5\u51b5\u5c31\u5f88\u56f0\u96be\u4e86\u3002<\/p>\n<p>\u6216\u8bb8\u53ef\u4ee5\u901a\u8fc7\u524d\u7aef\u7684 Web \u670d\u52a1\u5668\uff08\u6bd4\u5982 Nginx\uff09\u8fdb\u884c URL \u91cd\u5199\uff0c\u7136\u540e\u5728\u8f6c\u53d1\u5230\u540e\u7aef\u7684\u5e94\u7528\u670d\u52a1\u5668\uff0c\u7531\u5e94\u7528\u670d\u52a1\u5668\u6765\u8bb0\u5f55\u8bbf\u95ee\u65e5\u5fd7\u3002\u8fd9\u663e\u7136\u591a\u4e86\u4e00\u5c42\u590d\u6742\u6027\uff0c\u800c\u4e14\u6bcf\u65b0\u589e\u4e00\u4e2a API \u96be\u9053\u53c8\u5f97\u53bb Web \u670d\u52a1\u5668\u4e0a\u65b0\u589e\u4e00\u6761 URL \u89c4\u5219\uff1f\uff1f<\/p>\n<p>\u5728 Spring MVC \u91cc\u9762\uff0c\u62bd\u53d6 URL \u91cc\u7684\u53c2\u6570\u8fd8\u9700\u8981\u4e00\u4e2a\u6ce8\u89e3\uff0c\u4e0d\u5982\u8bf7\u6c42\u53c2\u6570\u65b9\u4fbf\u3002<\/p>\n<p>\u6211\u89c9\u5f97\uff1a\u5bf9\u6bcf\u4e2a API \u7684 URL \u8fdb\u884c\u89c4\u8303\u5316\u662f\u5f88\u91cd\u8981\u7684\uff0c\u4f46\u4e0d\u5e94\u8be5\u5f15\u5165 URL \u53c2\u6570\u5316\u3002<\/p>\n<hr\/>\n<p>\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u5fae\u4fe1\u516c\u4f17\u53f7: <strong>coderbee\u7b14\u8bb0<\/strong>\uff0c\u53ef\u4ee5\u66f4\u53ca\u65f6\u56de\u590d\u4f60\u7684\u8ba8\u8bba\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"258\" height=\"258\" src=\"https:\/\/coderbee.net\/wp-content\/uploads\/2019\/01\/coderbee-note.jpg\" class=\"alignnone size-full wp-image-1707\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>RESTful \u662f\u4ec0\u4e48\uff1f \u6765\u81ea\u300aSpring \u5b9e\u6218\u300b\uff1a REST \u7ec4\u6210\uff1a\u8868\u8ff0\u6027\u3001 &hellip; <a href=\"https:\/\/coderbee.net\/index.php\/web\/20140822\/1013\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[185],"_links":{"self":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/1013"}],"collection":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/comments?post=1013"}],"version-history":[{"count":3,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/1013\/revisions"}],"predecessor-version":[{"id":1016,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/1013\/revisions\/1016"}],"wp:attachment":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/media?parent=1013"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/categories?post=1013"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/tags?post=1013"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}