{"id":3196,"date":"2018-10-10T18:00:32","date_gmt":"2018-10-10T10:00:32","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=3196"},"modified":"2018-10-10T18:00:32","modified_gmt":"2018-10-10T10:00:32","slug":"restful-api-url-%e8%ae%be%e8%ae%a1","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=3196","title":{"rendered":"RESTful API URL \u8bbe\u8ba1"},"content":{"rendered":"<p>\n\t<a href=\"http:\/\/www.ruanyifeng.com\/blog\/2011\/09\/restful.html\" target=\"_blank\">RESTful<\/a>&nbsp;\u662f\u76ee\u524d\u6700\u6d41\u884c\u7684 API \u8bbe\u8ba1\u89c4\u8303\uff0c\u4e5f\u662f\u5404\u516c\u53f8\u62db\u8058\u9762\u8bd5\u7684\u9879\u76ee\u4e4b\u4e00\u3002\u5f88\u591a\u4eba\u5bf9 RESTful API \u7684\u8bbe\u8ba1\u8fd8\u4e0d\u662f\u5f88\u89c4\u8303\uff0c\u4e8e\u662f\u4fbf\u6709\u4e86\u672c\u6587\u3002\n<\/p>\n<p>\n\tURL \u7684\u8bbe\u8ba1\uff0c\u4e00\u822c\u6211\u4eec\u4f1a\u91c7\u7528\uff1a\u52a8\u8bcd + \u5bbe\u8bed\u7684\u5f62\u5f0f\u8868\u793a\u3002\n<\/p>\n<p>\n\tRESTful \u7684\u6838\u5fc3\u601d\u60f3\u5c31\u662f\uff0c\u5ba2\u6237\u7aef\u53d1\u51fa\u7684\u6570\u636e\u64cd\u4f5c\u6307\u4ee4\u90fd\u662f&quot;\u52a8\u8bcd + \u5bbe\u8bed&quot;\u7684\u7ed3\u6784\u3002\u6bd4\u5982\uff0cGET \/articles\u8fd9\u4e2a\u547d\u4ee4\uff0cGET\u662f\u52a8\u8bcd\uff0c\/articles\u662f\u5bbe\u8bed\u3002\n<\/p>\n<p>\n\t\u52a8\u8bcd\u901a\u5e38\u5c31\u662f\u4e94\u79cd HTTP \u65b9\u6cd5\uff0c\u5bf9\u5e94 CRUD \u64cd\u4f5c\u3002\n<\/p>\n<ul>\n<li>\n\t\tGET\uff1a\u8bfb\u53d6\uff08Read\uff09\n\t<\/li>\n<li>\n\t\tPOST\uff1a\u65b0\u5efa\uff08Create\uff09\n\t<\/li>\n<li>\n\t\tPUT\uff1a\u66f4\u65b0\uff08Update\uff09\n\t<\/li>\n<li>\n\t\tPATCH\uff1a\u66f4\u65b0\uff08Update\uff09\uff0c\u901a\u5e38\u662f\u90e8\u5206\u66f4\u65b0\n\t<\/li>\n<li>\n\t\tDELETE\uff1a\u5220\u9664\uff08Delete\uff09\n\t<\/li>\n<\/ul>\n<p>\n\t\u6839\u636e HTTP \u89c4\u8303\uff0c\u52a8\u8bcd\u4e00\u5f8b\u5927\u5199\u3002\n<\/p>\n<p>\n\t\u6709\u4e9b\u5ba2\u6237\u7aef\u53ea\u80fd\u4f7f\u7528GET\u548cPOST\u8fd9\u4e24\u79cd\u65b9\u6cd5\u3002\u670d\u52a1\u5668\u5fc5\u987b\u63a5\u53d7POST\u6a21\u62df\u5176\u4ed6\u4e09\u4e2a\u65b9\u6cd5\uff08PUT\u3001PATCH\u3001DELETE\uff09\u3002\n<\/p>\n<p>\n\t\u8fd9\u65f6\uff0c\u5ba2\u6237\u7aef\u53d1\u51fa\u7684 HTTP \u8bf7\u6c42\uff0c\u8981\u52a0\u4e0aX-HTTP-Method-Override\u5c5e\u6027\uff0c\u544a\u8bc9\u670d\u52a1\u5668\u5e94\u8be5\u4f7f\u7528\u54ea\u4e00\u4e2a\u52a8\u8bcd\uff0c\u8986\u76d6POST\u65b9\u6cd5\u3002\n<\/p>\n<pre class=\"brush:bash;\">\r\nPOST \/api\/Person\/4 HTTP\/1.1  \r\nX-HTTP-Method-Override: PUT<\/pre>\n<p>\n\t\u4e0a\u9762\u4ee3\u7801\u4e2d\uff0cX-HTTP-Method-Override\u6307\u5b9a\u672c\u6b21\u8bf7\u6c42\u7684\u65b9\u6cd5\u662fPUT\uff0c\u800c\u4e0d\u662fPOST\u3002\n<\/p>\n<p>\n\t\u5728 SpringMVC \u4e2d\u4f1a\u6dfb\u52a0\u4e00\u4e2a&nbsp;HiddenHttpMethodFilter \u8fc7\u6ee4\u5668\u3002\u5b83\u4f1a\u5c06\u8868\u5355\u4e0a\u9690\u85cf\u57df_method\u5c5e\u6027\u6539\u4e3aput\u6216\u8005delete\u7b49\u518d\u8fdb\u884c\u63d0\u4ea4\u3002\u56e0\u4e3a\u53ea\u6709form\u8868\u5355\u624d\u5177\u6709post\u65b9\u6cd5,\u800c\u8fd9\u4e2a\u8fc7\u6ee4\u5668\u4e5f\u53ea\u80fd\u5c06post\u65b9\u6cd5\u8f6c\u5316,get\u5219\u4e0d\u884c\u3002\u4e0d\u61c2\u7684\u53ef\u4ee5\u770b\u8fd9\u7bc7\u6587\u7ae0\uff1a<a href=\"https:\/\/blog.csdn.net\/jaryle\/article\/details\/73656426\">https:\/\/blog.csdn.net\/jaryle\/article\/details\/73656426<\/a>\u3002\n<\/p>\n<p>\n\t\u5bbe\u8bed\u5c31\u662f API \u7684 URL\uff0c\u662f HTTP \u52a8\u8bcd\u4f5c\u7528\u7684\u5bf9\u8c61\u3002\u5b83\u5e94\u8be5\u662f\u540d\u8bcd\uff0c\u4e0d\u80fd\u662f\u52a8\u8bcd\u3002\u6bd4\u5982\uff0c\/articles\u8fd9\u4e2a URL \u5c31\u662f\u6b63\u786e\u7684\uff0c\u800c\u4e0b\u9762\u7684 URL \u4e0d\u662f\u540d\u8bcd\uff0c\u6240\u4ee5\u90fd\u662f\u9519\u8bef\u7684\u3002\n<\/p>\n<ul>\n<li>\n\t\t\/getAllCars\n\t<\/li>\n<li>\n\t\t\/createNewCar\n\t<\/li>\n<li>\n\t\t\/deleteAllRedCars\n\t<\/li>\n<\/ul>\n<p>\n\t\u65e2\u7136 URL \u662f\u540d\u8bcd\uff0c\u90a3\u4e48\u5e94\u8be5\u4f7f\u7528\u590d\u6570\uff0c\u8fd8\u662f\u5355\u6570\uff1f\n<\/p>\n<p>\n\t\u8fd9\u6ca1\u6709\u7edf\u4e00\u7684\u89c4\u5b9a\uff0c\u4f46\u662f\u5e38\u89c1\u7684\u64cd\u4f5c\u662f\u8bfb\u53d6\u4e00\u4e2a\u96c6\u5408\uff0c\u6bd4\u5982GET \/articles\uff08\u8bfb\u53d6\u6240\u6709\u6587\u7ae0\uff09\uff0c\u8fd9\u91cc\u660e\u663e\u5e94\u8be5\u662f\u590d\u6570\u3002\n<\/p>\n<p>\n\t\u4e3a\u4e86\u7edf\u4e00\u8d77\u89c1\uff0c\u5efa\u8bae\u90fd\u4f7f\u7528\u590d\u6570 URL\uff0c\u6bd4\u5982GET \/articles\/2\u8981\u597d\u4e8eGET \/article\/2\u3002\n<\/p>\n<p>\n\t\u5e38\u89c1\u7684\u60c5\u51b5\u662f\uff0c\u8d44\u6e90\u9700\u8981\u591a\u7ea7\u5206\u7c7b\uff0c\u56e0\u6b64\u5f88\u5bb9\u6613\u5199\u51fa\u591a\u7ea7\u7684 URL\uff0c\u6bd4\u5982\u83b7\u53d6\u67d0\u4e2a\u4f5c\u8005\u7684\u67d0\u4e00\u7c7b\u6587\u7ae0\u3002\n<\/p>\n<pre class=\"brush:bash;\">\r\nGET \/authors\/12\/categories\/2<\/pre>\n<p>\n\t\u8fd9\u79cd URL \u4e0d\u5229\u4e8e\u6269\u5c55\uff0c\u8bed\u4e49\u4e5f\u4e0d\u660e\u786e\uff0c\u5f80\u5f80\u8981\u60f3\u4e00\u4f1a\uff0c\u624d\u80fd\u660e\u767d\u542b\u4e49\u3002\n<\/p>\n<p>\n\t\u66f4\u597d\u7684\u505a\u6cd5\u662f\uff0c\u9664\u4e86\u7b2c\u4e00\u7ea7\uff0c\u5176\u4ed6\u7ea7\u522b\u90fd\u7528\u67e5\u8be2\u5b57\u7b26\u4e32\u8868\u8fbe\u3002\n<\/p>\n<pre class=\"brush:bash;\">\r\nGET \/authors\/12?categories=2<\/pre>\n<p>\n\t\u4e0b\u9762\u662f\u53e6\u4e00\u4e2a\u4f8b\u5b50\uff0c\u67e5\u8be2\u5df2\u53d1\u5e03\u7684\u6587\u7ae0\u3002\u4f60\u53ef\u80fd\u4f1a\u8bbe\u8ba1\u6210\u4e0b\u9762\u7684 URL\u3002\n<\/p>\n<pre class=\"brush:bash;\">\r\nGET \/articles\/published<\/pre>\n<p>\n\t\u67e5\u8be2\u5b57\u7b26\u4e32\u7684\u5199\u6cd5\u660e\u663e\u66f4\u597d\u3002\n<\/p>\n<pre class=\"brush:bash;\">\r\nGET \/articles?published=true<\/pre>\n<p>\n\tRESTful API \u6700\u597d\u7684\u4f8b\u5b50\u5c31\u662f github \u7f51\u7ad9\u3002\u5927\u5bb6\u7ecf\u5e38\u4f7f\u7528\uff0c\u4e00\u5b9a\u4e0d\u964c\u751f\u3002\u6240\u4ee5\u53ef\u4ee5\u501f\u9274 github \u4e0a\u7684\u8d44\u6e90\u547d\u540d\u65b9\u5f0f\u6765\u5f00\u53d1\u81ea\u5df1\u7684\u4ea7\u54c1\uff0c\u8bbe\u8ba1\u81ea\u5df1\u7684&nbsp;RESTful API \u548c URL\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=3196\">RESTful API URL \u8bbe\u8ba1<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>RESTful&nbsp;\u662f\u76ee\u524d\u6700\u6d41\u884c\u7684 API \u8bbe\u8ba1\u89c4\u8303\uff0c\u4e5f\u662f\u5404\u516c\u53f8\u62db\u8058\u9762\u8bd5\u7684\u9879\u76ee\u4e4b\u4e00\u3002\u5f88\u591a\u4eba\u5bf9 RESTf [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,5,6],"tags":[1047,1366,810,470,490],"class_list":["post-3196","post","type-post","status-publish","format-standard","hentry","category-html5","category-java","category-yyzt","tag-targeturl","tag-beannameurlhandlermapping","tag-openurl","tag-restful","tag-springmvcrestful"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3196","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3196"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3196\/revisions"}],"predecessor-version":[{"id":3197,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3196\/revisions\/3197"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}