{"id":94752,"date":"2024-04-29T11:19:10","date_gmt":"2024-04-29T03:19:10","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=94752"},"modified":"2024-04-29T11:19:10","modified_gmt":"2024-04-29T03:19:10","slug":"rest-api-practice","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/rest-api-practice.html","title":{"rendered":"REST API \u8bbe\u8ba1\u4e0e\u5f00\u53d1\u5b9e\u8df5"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5728\u672c\u6587\u4e2d\uff0c\u6211\u7684\u76ee\u6807\u662f\u5411\u5927\u5bb6\u5c3d\u53ef\u80fd\u8be6\u7ec6\u7684\u89e3\u91caREST API\uff0c\u5305\u62ec\u7406\u8bba\u548c\u5f00\u53d1\u90e8\u5206\u3002\u4ee5\u4fbf\u5927\u5bb6\u80fd\u6e05\u695a\u7684\u4e86\u89e3\u4f55\u65f6\u7528\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u5b83\uff0c\u5305\u62ec\u5b83\u7684\u672c\u8d28\u662f\u4ec0\u4e48\u3002\u65e0\u8bba\u662f\u81ea\u5df1\u5f00\u53d1API\u8fd8\u662f\u4f7f\u7528\u7b2c\u4e09\u65b9API\uff0c\u90fd\u4f1a\u66f4\u52a0\u987a\u5229\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u50cfAlibaba,Baidu,Tecent,Toutiao\uff0cFacebook,Google,Amazon\u7b49\u516c\u53f8\u90fd\u62e5\u6709\u5f00\u653e\u7684RESTful API\u6216\u5f00\u653e\uff0c\u6211\u4eec\u53ef\u4ee5\u7533\u8bf7\u8bbf\u95ee\uff0c\u83b7\u53d6\u751a\u81f3\u5199\u5165\u6570\u636e\u3002<\/p>\n

\u6240\u6709\u7684\u4e8b\u60c5\u90fd\u8981\u95ee\u4e3a\u4ec0\u4e48\u3002\u4e3a\u4ec0\u4e48\u9700\u8981REST API \uff1fREST\u4e3a\u4f55\u5982\u6b64\u666e\u53ca\uff1f<\/p>\n

\u5f53\u7136\uff0c\u4f20\u9012\u4fe1\u606f\u6709\u5f88\u591a\u79cd\u65b9\u5f0f\u3002\u5982Socket\uff0cREST\uff0cWebService\uff0cHTTP\u7b49\u3002<\/p>\n

REST\u4e0eHTTP\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/strong><\/div>\n

REST\u5f88\u7075\u6d3b\uff0c\u4e0eHTTP\u534f\u8bae\u517c\u5bb9\u3002\u5b83\u662f\u4e00\u4e2a\u67b6\u6784\u98ce\u683c\uff0c\u5e76\u975e\u6807\u51c6\uff0c\u7528\u5b83\u6765\u63d0\u4f9b\u5404\u79cd\u670d\u52a1\uff0c\u53ef\u4ee5\u7528\u5404\u79cd\u7f16\u7a0b\u8bed\u8a00\u6765\u5b9e\u73b0\u3002<\/p>\n

\u5728\u672c\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u7684\u76ee\u6807\u662f\u4e00\u8d77\u6e05\u6670\u7684\u4e86\u89e3 REST\uff0c\u77e5\u9053\u4f55\u65f6\u7528\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u5b83\uff0c\u4ee5\u53caREST\u7684\u672c\u8d28\u3002<\/p>\n

\u6211\u4eec\u5c06\u901a\u8fc7\u4e00\u4e9b\u57fa\u7840\u77e5\u8bc6\u548c\u5b9a\u4e49\uff0c\u5305\u62ecREST API\u7684\u6700\u4f73\u5b9e\u8df5\uff0c\u53ef\u4ee5\u8ba9\u5404\u4f4d\u80fd\u591f\u7528\u4efb\u4f55\u5f00\u53d1\u8bed\u8a00\u6765\u5b9e\u73b0REST API\u3002<\/p>\n

\u5efa\u8bae\u60a8\u6709HTTP\u534f\u8bae\u57fa\u7840\uff0c\u6216\u8005\u4e86\u89e3\u4e00\u90e8\u5206\uff0c\u53ef\u4ee5\u5145\u5206\u6d88\u5316\u8fd9\u90e8\u5206\u5185\u5bb9\u3002<\/p>\n

REST\u7684\u672c\u8d28<\/strong><\/div>\n

REST - Representational State Transfer\u662fRoy Field\u535a\u58eb\u521b\u7acb\u7684\u4e00\u79cd\u67b6\u6784\u98ce\u683c\uff0c\u4ed6\u5728UC Irvine\u7684\u8bba\u6587\u4e2d\u63cf\u8ff0\u4e86\u67b6\u6784\u98ce\u683c\u4e0e\u57fa\u4e8eWeb\u7684\u8f6f\u4ef6\u67b6\u6784\u8bbe\u8ba1\uff0c\u5e76\u4f7f\u7528HTTP 1.1\u5f00\u53d1\u3002<\/p>\n

\u6211\u4eec\u4f7f\u7528REST\u505a\u4e3a\u4e92\u8054\u7f51\u4e0a\u4e0d\u540c\u8ba1\u7b97\u673a\u7cfb\u7edf\u95f4\u901a\u4fe1\u7684\u4e00\u79cd\u65b9\u5f0f\u3002<\/p>\n

REST\u7ed1\u5b9aHTTP<\/p>\n

\u6839\u636eREST\u5b9a\u4e49\uff0c\u5e76\u975e\u5982\u6b64\u3002\u5c3d\u7ba1\u4eba\u4eec\u53ef\u4ee5\u4f7f\u7528\u5176\u5b83\u4e00\u4e9bREST\u5e94\u7528\u7a0b\u5e8f\u534f\u8bae\uff0c\u4f46\u5728\u6d89\u53caREST\u5b9e\u73b0\u65f6\uff0cHTTP\u4ecd\u7136\u662f\u5e94\u7528\u7a0b\u5e8f\u534f\u8bae\u4e2d\u65e0\u53ef\u4e89\u8fa9\u7684\u4e3b\u6d41\u3002<\/p>\n

RESTful API\u7684\u542b\u4e49<\/strong><\/div>\n

RESTful\u6709\u4e0b\u5217\u4e00\u4e9b\u7279\u70b9\uff1a<\/p>\n

1\u3001\u5ba2\u6237\u7aef\/\u670d\u52a1\u5668\u67b6\u6784\uff1a\u5b8c\u6574\u7684\u670d\u52a1\u7531\u524d\u7aef\u201c\u5ba2\u6237\u7aef\u201d\u548c\u6574\u4e2a\u7cfb\u7edf\u7684\u540e\u7aef\u201c\u670d\u52a1\u5668\u201d\u7ec4\u6210\u3002<\/p>\n

2\u3001\u65e0\u72b6\u6001\uff1a\u670d\u52a1\u5668\u5728\u4e0d\u540c\u8bf7\u6c42\u4e2d\u95f4\u4e0d\u4fdd\u5b58\u4efb\u4f55\u72b6\u6001\u3002\u4f1a\u8bdd\u7684\u72b6\u6001\u5b8c\u5168\u7531\u5ba2\u6237\u7aef\u8d1f\u8d23\u3002\u6839\u636eREST\u7684\u5b9a\u4e49\uff1a\u6240\u6709REST\u4ea4\u4e92\u90fd\u662f\u65e0\u72b6\u6001\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u6bcf\u4e2a\u8bf7\u6c42\u90fd\u5305\u542b\u8fde\u63a5\u5668\u7406\u89e3\u8bf7\u6c42\u6240\u9700\u7684\u5168\u90e8\u4fe1\u606f\uff0c\u800c\u4e0d\u53d7\u4efb\u4f55\u5148\u524d\u53ef\u80fd\u53d1\u751f\u7684\u8bf7\u6c42\u5f71\u54cd\u3002<\/p>\n

3\u3001\u53ef\u7f13\u5b58\uff1a\u5ba2\u6237\u7aef\u5e94\u8be5\u80fd\u591f\u5c06\u54cd\u5e94\u5b58\u50a8\u5728\u7f13\u5b58\u4e2d\uff0c\u4ee5\u4fbf\u83b7\u5f97\u66f4\u597d\u7684\u6027\u80fd\u3002<\/p>\n

RESTful API\u9075\u5faa\u4ee5\u4e0a\u8fd9\u4e9b\u89c4\u5219\uff0c\u5e76\u4f7f\u7528HTTP\u65b9\u6cd5\u6765\u64cd\u4f5c\u8d44\u6e90\u96c6\u7684\u670d\u52a1\u3002<\/p>\n

\u4e3a\u4ec0\u4e48\u9700\u8981\u7528 Restful API<\/strong><\/div>\n

\u56e0\u4e3a\u5b83\u4eec\u63d0\u4f9b\u4e86\u4e00\u79cd\u7b80\u5355\u3001\u7075\u6d3b\u548c\u53ef\u6269\u5c55\u7684\u65b9\u5f0f\u6765\u5f00\u53d1Web\u901a\u4fe1\u7684\u5206\u5e03\u5f0f\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

\u6211\u4eec\u53ef\u80fd\u6709\u5f88\u591aREST API\u3002\u5982\u679c\u4e1a\u52a1\u8db3\u591f\u5e7f\uff0c\u9700\u8981\u5f00\u653e\u7684\u670d\u52a1\u4e5f\u4f1a\u53d8\u5f97\u590d\u6742\u3002<\/p>\n

\u5f00\u53d1\u8005\u9700\u8981\u4e00\u4e9b\u5b9e\u7528\u4e3b\u4e49\u624d\u80fd\u505a\u51fa\u597d\u7684\u5e94\u7528\u548c\u670d\u52a1\u3002<\/p>\n

\u7406\u8bba\u5bf9\u4e8e\u8ba4\u77e5\u7406\u89e3\u5f88\u91cd\u8981\uff0c\u4f46\u7406\u8bba\u7684\u5b9e\u65bd\u624d\u662f\u533a\u5206\u4f18\u52a3\u5e94\u7528\u5dee\u5f02\u7684\u68c0\u9a8c\u6807\u51c6\u3002\u4e3a\u6b64\uff0c\u6211\u4eec\u8981\u806a\u660e\u7684\u5de5\u4f5c\uff0c\u4f46\u4e00\u5b9a\u8981\u8bb0\u5f97\uff0c\u6700\u7ec8\u7528\u6237\u624d\u662f\u7b2c\u4e00\u4f18\u5148\u7ea7\uff0c\u662f\u6700\u9ad8\u4ef7\u503c\u3002<\/p>\n

\u6211\u4eec\u77e5\u9053\u4e86\u91cd\u70b9\uff0c\u8ba9API\u505a\u5f97\u5f3a\u5927\u6613\uff0c\u8ba9\u7528\u6237\u7684\u5de5\u4f5c\u4e5f\u53d8\u5f97\u66f4\u5bb9\u6613 \u3002<\/p>\n

\u62bd\u8c61\u4e0e\u5177\u4f53\u4e1a\u52a1 API<\/strong><\/div>\n

\u5728\u5f00\u53d1\u8f6f\u4ef6\u65f6\uff0c\u6211\u4eec\u4f1a\u7ecf\u5e38\u4f7f\u7528\u9762\u5411\u5bf9\u8c61\u7684\u62bd\u8c61\u548c\u591a\u6001\u6765\u5f00\u53d1\u5e94\u7528\u7a0b\u5e8f\u3002\u8fd9\u6837\u53ef\u4ee5\u6700\u5927\u5316\u91cd\u7528\u4ee3\u7801\u3002<\/p>\n

\u90a3\u4e48\uff0c\u6211\u4eec\u662f\u4e0d\u662f\u4e5f\u5e94\u8be5\u8fd9\u6837\u5f00\u53d1REST API\uff1f<\/p>\n

\u5230\u5f00\u53d1API\u7684\u60c5\u51b5\u5c31\u4e0d\u540c\u4e86\uff0c\u5bf9\u4e8eREST API\uff0c\u5177\u4f53\u6bd4\u62bd\u8c61\u66f4\u597d\u3002\u4e5f\u5c31\u662f\u5b8c\u6210\u5b9e\u9645\u7684\u529f\u80fd\u66f4\u597d\u3002\u6211\u4eec\u6765\u770b\u4e00\u4e9b\u5b9e\u4f8b\uff1a<\/p>\n

\u6709\u4e24\u4e2aapi\u7248\u672c\uff1a<\/p>\n

\/entities<\/p>\n

\/entitie<\/p>\n

\/owners<\/p>\n

\/blogs<\/p>\n

\/blogposts<\/p><\/blockquote>\n

\u60a8\u505a\u4e3a\u5f00\u53d1\u8005\uff0c\u54ea\u4e2a\u63cf\u8ff0\u4f1a\u66f4\u6e05\u695a\uff0c\u60a8\u613f\u610f\u7528\u54ea\u4e2aAPI\uff1f\u6211\u9009\u62e9\u7b2c\u4e8c\u4e2a\u3002<\/p>\n

URI\u683c\u5f0f\uff0c\u4f7f\u7528\u540d\u8bcd\u800c\u975e\u52a8\u8bcd<\/strong><\/p>\n

\u4e0b\u9762\u662fAPI\u5f00\u53d1\u7684\u53e6\u4e00\u4e2a\u6700\u4f73\u5b9e\u8df5\u3002\u6211\u4eec\u5982\u4f55\u683c\u5f0f\u5316\u4f60\u7684\u7ed3\u70b9\uff1f\u5982\u679c\u4f60\u4f7f\u7528\u7f16\u7801\u7684\u65b9\u6cd5\u6765\u547d\u540dURI\u7ed3\u70b9\uff0c\u4f1a\u662f\u4ee5\u4e0b\u7684\u7ed3\u679c\uff1a<\/p>\n

\/getAllBlogPosts<\/p>\n

\/updateBlogPost\/12<\/p>\n

\/deleteBlogPost\/12<\/p>\n

\/updateAuthor\/3<\/p>\n

\/deleteAuthor\/3<\/p><\/blockquote>\n

\u6211\u60f3\u60a8\u5df2\u7ecf\u660e\u767d\uff0c\u8fd9\u4f1a\u6709\u5f88\u591a\u4e2aURL\u7ed3\u70b9\uff0c\u6bcf\u4e2a\u7ed3\u70b9\u53ea\u505a\u4e00\u4ef6\u4e8b\u60c5\u3002<\/p>\n

\u6211\u4eec\u8981\u6709\u4e00\u4e2a\u66f4\u7cfb\u7edf\u7684\u547d\u540d\u6765\u7cbe\u7b80\u68b3\u7406\u4e0a\u9762\u8fd9\u4e2a\u644a\u5b50\u3002\u5148\u628a\u8d44\u6e90\u7528\u540d\u8bcd\u6765\u63cf\u8ff0\uff0c\u628aHTTP\u65b9\u6cd5\u6362\u6210\u52a8\u8bcd\u3002\u4e8e\u662f\u6211\u4eec\u4f1a\u5f97\u5230\u4e0b\u9762\u8fd9\u6837\u7684\u7ed3\u679c\uff1a<\/p>\n

GET \/blogpsots - \u53d6\u5f97\u6240\u6709\u7684\u535a\u5ba2<\/p>\n

GET \/blogposts\/12 - \u53d6\u5f97ID\u4e3a12\u7684\u535a\u5ba2<\/p>\n

POST \/blogposts - \u6dfb\u52a0\u4e00\u4e2a\u65b0\u7684\u535a\u5ba2\uff0c\u8fd4\u56de\u9519\u8bef\u4fe1\u606f<\/p>\n

DELETE \/blogposts\/12 - \u5220\u9664ID\u4e3a12\u7684\u535a\u5ba2<\/p>\n

GET \/author\/3\/blogposts - \u83b7\u53d6ID\u4e3a3\u7684\u4f5c\u8005\u5168\u90e8\u535a\u5ba2<\/p><\/blockquote>\n

\u8fd9\u6837\uff0c\u4e00\u4e2a\u66f4\u7b80\u6d01\uff0c\u7cbe\u786e\u7684API \u5c31\u51fa\u73b0\u4e86\u3002\u5bf9\u4e8e\u4f7f\u7528\u7684\u7528\u6237\u6765\u8bb2\uff0c\u4ed6\u4f1a\u9a6c\u4e0a\u6e05\u695a\u3002\u5f53\u7136\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u5355\u6570\u5f62\u5f0f\u800c\u4e0d\u662f\u590d\u6570\u5f62\u5f0f\uff0c\u8fd9\u6837\u663e\u5f97\u8d44\u6e90\u540d\u79f0\u66f4\u4e3a\u6574\u6d01\uff0c\u60a8\u6839\u636e\u81ea\u5df1\u7684\u559c\u597d\uff0c\u8fd9\u70b9\u53d6\u51b3\u4e8e\u81ea\u5df1\u3002<\/p>\n

\u9519\u8bef\u5904\u7406<\/strong><\/div>\n

\u672c\u9636\u6bb5\u662fAPI\u5f00\u53d1\u7684\u53e6\u4e00\u4e2a\u91cd\u8981\u65b9\u9762\u3002\u6709\u597d\u51e0\u4e2a\u5f88\u597d\u7684\u65b9\u6cd5\u6765\u5904\u7406\u9519\u8bef\u3002<\/p>\n

\u6211\u4eec\u6765\u770b\u4e00\u4e9b\u9ad8\u7ea7\u7684\u5f00\u53d1\u72d7\u662f\u548b\u5e72\u7684\uff1a<\/p>\n

Twitter:<\/strong><\/span><\/div>\n
\u8bf7\u6c42\uff1aGET https:\/\/api.twitter.com\/1.1\/account\/settings.json\r\n\r\n\u54cd\u5e94\uff1a\u72b6\u6001\u7801 400\r\n\r\n{\"errors\":[{\"code\":215,\"message\":\"Bad Authentication data.\"}]}<\/pre>\n

Twitter\u7ed9\u6211\u4eec\u7684\u72b6\u6001\u7801\u548c\u9519\u8bef\u7801\uff0c\u4ee5\u53ca\u4e00\u4e2a\u7b80\u77ed\u8bf4\u660e\u3002<\/p>\n

Facebook\uff1a<\/strong><\/span><\/div>\n
\u8bf7\u6c42\uff1aGET https:\/\/graph.facebook.com\/me\/photos\r\n\r\n\u54cd\u5e94\uff1a\u72b6\u6001\u7801 400\r\n\r\n{\r\n\r\n\"error\": {\r\n\r\n\"message\": \"An active access token must be used to query information about the current user.\",\r\n\r\n\"type\": \"OAuthException\",\r\n\r\n\"code\": 2500,\r\n\r\n\"fbtrace_id\": \"DzkTMkgIA7V\"\r\n\r\n}\r\n\r\n}<\/pre>\n

Facebook\u7ed9\u591f\u7ed9\u4f60\u4e00\u4e2a\u66f4\u5177\u4f53\u7684\u9519\u8bef\u4fe1\u606f\u3002<\/p>\n

Twilio\uff1a<\/strong><\/span><\/div>\n
\u8bf7\u6c42\uff1aGET https:\/\/api.twilio.com\/2010-04-01\/Accounts\/1234\/IncomingPhoneNumbers\/1234\r\n\r\n\u54cd\u5e94\uff1a\u72b6\u6001\u7801 404\r\n\r\n<?xml version='1.0' encoding='UTF-8'?>\r\n\r\n<TwilioResponse>\r\n\r\n<RestException>\r\n\r\n<Code>20404<\/Code>\r\n\r\n<Message>The requested resource \/2010-04-01\/Accounts\/1234\/IncomingPhoneNumbers\/1234 was not found<\/Message>\r\n\r\n<MoreInfo>https:\/\/www.twilio.com\/docs\/errors\/20404<\/MoreInfo>\r\n\r\n<Status>404<\/Status>\r\n\r\n<\/RestException>\r\n\r\n<\/TwilioResponse><\/pre>\n

Twilio\u7ed9\u6211\u4eec\u4e00\u4e2aXML\u54cd\u5c31\u683c\u5f0f\uff0c\u5e76\u4e14\u80fd\u591f\u94fe\u5230\u4f60\u80fd\u627e\u5230\u9519\u8bef\u7ec6\u8282\u7684\u6587\u6863\u3002<\/p>\n

\u6211\u4eec\u770b\u5230\uff0c\u4e0d\u540c\u7684\u5f00\u53d1\u8005\u63d0\u4f9b\u65b9\u6cd5\u5b58\u5728\u4e00\u4e9b\u533a\u522b\u3002\u4f46\u662f\u8fd9\u4e9b\u5f00\u653e\u5e73\u53f0\u90fd\u63d0\u4f9b\u4e86\u5177\u4f53\u7684\u9519\u8bef\u4fe1\u606f\uff0c\u4e0d\u4f1a\u53ea\u7b80\u5355\u544a\u8bc9\u7528\u6237\u4e0d\u53ef\u7528\uff0c\u8ba9\u7528\u6237\u4e0d\u77e5\u9053\u53d1\u751f\u4e86\u4ec0\u4e48\uff0c\u8ba9\u4ed6\u4eec\u5728\u641c\u7d22\u5f15\u64ce\u65e0\u76ee\u7684\u7684\u641c\u7d22\u53ea\u4f1a\u6d6a\u8d39\u65f6\u95f4\u3002<\/p>\n

\"\"<\/p>\n

 <\/p>\n

\u8fd4\u56de\u72b6\u6001\u7801<\/strong><\/div>\n

\u5728\u8bbe\u8ba1REST API\u65f6\uff0c\u9700\u8981\u4f7f\u7528HTTP\u72b6\u6001\u4ee3\u7801\u4e0eAPI\u8fdb\u884c\u901a\u4fe1\u3002<\/p>\n

\u5982\u4f60\u6240\u60f3\uff0cHTTP\u6709\u5f88\u591a\u73b0\u6210\u72b6\u6001\u7801\uff0c\u53ef\u4ee5\u63cf\u8ff0\u4e00\u4e9b\u53ef\u80fd\u7684\u54cd\u5e94\u3002<\/p>\n

\u4f46\u662f\uff0c\u6211\u4eec\u5e94\u8be5\u7528\u591a\u5c11\uff1f\u6211\u4eec\u5e94\u8be5\u5bf9\u6bcf\u4e00\u79cd\u60c5\u51b5\u90fd\u6709\u4e25\u683c\u7684\u72b6\u6001\u7f16\u7801\u4e48\uff1f<\/p>\n

HTTP\u72b6\u6001\u7801\u8d85\u8fc770\u4e2a\u72b6\u6001\uff0c\u4f60\u77e5\u9053\u4ed6\u4eec\u7684\u6838\u5fc3\u5417\uff1f API\u7528\u6237\u662f\u5426\u4f1a\u7528\u5230\u5b83\u4eec\uff0c\u907f\u514d\u8ba9\u5927\u5bb6\u518d\u53bb\u67e5\u3002\u6211\u4eec\u5927\u591a\u6570\u90fd\u719f\u6089\u4ee5\u4e0b\u7684\u72b6\u6001\u7801\uff1a<\/p>\n

200 OK<\/p>\n

400 Bad Request<\/p>\n

500 Internal Server Error<\/p><\/blockquote>\n

\u6211\u4eec\u5148\u4ece\u8fd9\u4e09\u70b9\u5f00\u59cb\uff0c\u6765\u9010\u6b65\u8986\u76d6REST API\u7684\u5927\u90e8\u5206\u529f\u80fd\u3002<\/p>\n

\u5176\u5b83\u5e38\u89c1\u7684\u72b6\u6001\u7801\uff1a<\/p>\n

201 Created<\/p>\n

204 No Content<\/p>\n

401 Unauthorized<\/p>\n

403 Forbidden<\/p>\n

404 Not Found<\/p><\/blockquote>\n

\u53ef\u4ee5\u901a\u8fc7\u529f\u80fd\u5e2e\u52a9\u7528\u6237\u5feb\u901f\u627e\u51fa\u7ed3\u679c\u3002 \u5982\u679c\u89c9\u5f97\u72b6\u6001\u4ee3\u7801\u4e0d\u591f\u5728\u9519\u8bef\u5904\u7406\u663e\u793a\u63cf\u8ff0\u6027\u5185\u5bb9\uff0c\u90a3\u4e48\u5e94\u8be5\u5305\u542b\u67d0\u7c7b\u578b\u7684\u6d88\u606f\u3002 \u518d\u901a\u8fc7\u4ee3\u7801\u548c\u63cf\u8ff0\u6027\u4fe1\u606f\u6765\u5e2e\u52a9API\u7528\u6237\u3002<\/p>\n

\u5b89\u5168<\/strong><\/div>\n

REST API\u5b89\u5168\u6027\u4f9d\u8d56\u4e8e\u6807\u51c6\u7684HTTP\u673a\u5236\uff0c\u5982\u57fa\u672c\u8ba4\u8bc1\u6216\u6458\u8981\u8ba4\u8bc1 \u3002<\/p>\n

\u6bcf\u4e2a\u8bf7\u6c42\u90fd\u5e94\u8be5\u901a\u8fc7HTTPS\u8fdb\u884c \u3002<\/p>\n

\u63d0\u9ad8REST API\u7684\u5b89\u5168\u6027\u6709\u5f88\u591a\u6280\u5de7\uff0c\u4f46\u662f\u7531\u4e8eREST\u7684\u65e0\u72b6\u6001\u7279\u6027\uff0c\u5728\u5b9e\u73b0\u5b83\u4eec\u65f6\u8bf7\u52a1\u5fc5\u5c0f\u5fc3\u8c28\u614e\u3002 \u6bd4\u5982\u6700\u540e\u4e00\u4e2a\u8bf7\u6c42\u7684\u72b6\u6001\u672a\u8fd4\u56de\uff0c \u5ba2\u6237\u7aef\u5e94\u8be5\u5b58\u50a8\u548c\u9a8c\u8bc1\u72b6\u6001\u3002<\/p>\n

\u53e6\u5916\uff0c\u4f7f\u7528\u65f6\u95f4\u6233\u548c\u8bb0\u5f55\u8bf7\u6c42\u5bf9\u6211\u4eec\u4e5f\u6709\u5f88\u5927\u5e2e\u52a9\u3002<\/p>\n

\u5173\u4e8e\u6b64\u8bdd\u9898\u8fd8\u6709\u5f88\u591a\u8981\u8bf4\u7684\uff0c\u4f46\u4e0d\u5728\u672c\u6587\u7684\u8ba8\u8bba\u8303\u56f4\u5185\u3002 \u5982\u679c\u60a8\u60f3\u4e86\u89e3\u66f4\u591a\u5173\u4e8eHTTP\u5b89\u5168\u7684\u4fe1\u606f\uff0c\u8bf7\u67e5\u960521CTO\u516c\u4f17\u53f7\u6216\u793e\u533a\u7f51\u7ad9\u3002<\/p>\n

REST API\u7248\u672c\u63a7\u5236<\/strong><\/div>\n

\u6211\u4eec\u5df2\u7ecf\u7f16\u5199\u4e86REST API\uff0c\u8bb8\u591a\u7528\u6237\u5df2\u7ecf\u7528\u4e0a\u4e86\u5b83\uff0c\u6211\u4eec\u5bf9\u6b64\u611f\u5230\u6ee1\u610f\u3002<\/p>\n

\u4f46\u662f\u51fa\u73b0\u4e86\u65b0\u529f\u80fd\uff0c\u9700\u8981\u589e\u52a0\u6216\u4fee\u6539\u539f\u6709\u529f\u80fd\u548c\u65b9\u6cd5\uff0c\u6709\u53ef\u80fd\u8fd8\u662f\u5f88\u5927\u7684\u53d8\u5316\u3002<\/p>\n

\u4e0d\u5fc5\u62c5\u5fc3\uff0c\u6211\u4eec\u6709\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n

\u5728\u5f00\u59cb\u5f00\u53d1API\u4e4b\u524d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5c06API\u7248\u672c\u524d\u6dfb\u52a0\u5230URI\u7aef\u70b9\uff0c\u4ee5\u6b64\u8fbe\u5230API\u7248\u672c\u5316\u3002\u5982\u4e0b\uff1a<\/p>\n

https:\/\/api.21cto.com\/v1\/authors\/2\/blogposts\/13<\/a><\/p>\n

\u8fd9\u6837\uff0c\u53ea\u8981API\u53d1\u751f\u91cd\u5927\u53d8\u66f4\uff0c\u5c31\u53ef\u4ee5\u968f\u65f6\u589e\u52a0API\u7248\u672c\u53f7\uff08\u6bd4\u5982\uff0cv2\uff0cv3 ...\uff09\u3002 \u8fd9\u4e5f\u5411\u7528\u6237\u53d1\u51fa\u4fe1\u53f7\uff0c\u8bf4\u660e\u4e00\u4e9b\u91cd\u8981\u7684\u53d8\u5316\uff0c\u4f7f\u7528\u65b0\u7248\u672c\u65f6\u5e94\u8be5\u5c0f\u5fc3\u3002<\/p>\n

\u6587\u6863\u7684\u91cd\u8981\u6027<\/strong><\/div>\n

\u8fd9\u662f\u4e00\u4e2a\u7b80\u800c\u6613\u89c1\u7684\u65b9\u6cd5\u3002\u60a8\u53ef\u80fd\u662f\u4e16\u754c\u4e0a\u6700\u597d\u7684API\u5f00\u53d1\u8005\uff0c\u4f46\u5982\u82e5\u6ca1\u6709\u6587\u6863\uff0cAPI\u5c31\u5931\u53bb\u4e00\u534a\u7684\u751f\u547d\u529b\u3002<\/p>\n

\u6b63\u786e\u5b8c\u6574\u7684\u6587\u6863\u5bf9\u4e8e\u6bcf\u4e2a\u8f6f\u4ef6\u4ea7\u54c1\u548cWeb\u670d\u52a1\u90fd\u81f3\u5173\u91cd\u8981\u3002<\/p>\n

\u5f53\u7136\uff0c\u60a8\u5f53\u7136\u53ef\u4ee5\u901a\u8fc7\u4fdd\u6301\u4e00\u81f4\u5e76\u4f7f\u7528\u6e05\u6670\u7684\u63cf\u8ff0\u6027\u8bed\u6cd5\u6765\u8ba9\u7528\u6237\u5f88\u5bb9\u6613\u7684\u5b66\u4e60\u3002 \u4f46\u662f\uff0c\u597d\u7684\u6587\u6863\u4ecd\u7136\u4e0d\u53ef\u6216\u7f3a\u3002<\/p>\n

\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5f00\u653e\u5e73\u53f0API\u7684\u6587\u6863\u4f8b\u5b50\uff1a<\/p>\n

https:\/\/www.twilio.com\/docs\/api\/rest\/<\/a><\/p>\n

https:\/\/developers.facebook.com\/docs\/<\/a><\/p>\n

https:\/\/developers.google.com\/maps\/documentation\/<\/a><\/p>\n

\u6709\u5f88\u591a\u5de5\u5177\u53ef\u4ee5\u6211\u4eec\u5f00\u53d1\u548c\u8c03\u8bd5API\uff0c\u4f46\u662f\u4e0d\u8981\u5fd8\u4e86\u6dfb\u52a0\u4eba\u7684\u6d4b\u8bd5\u548c\u7406\u89e3\uff0c\u8ba9\u4e00\u4e2a\u4eba\u53ef\u4ee5\u6b63\u786e\u7406\u89e3\u60a8\u7684\u601d\u7ef4\u3002<\/p>\n

\u7ed3\u8bba<\/strong><\/div>\n

\u6211\u4eec\u5728\u672c\u6587\u4e86\u89e3\u4e86\u6784\u5efaREST API\u7684\u6982\u5ff5\uff0c\u5e76\u4ecb\u7ecd\u4e86\u4e00\u4e9bREST API\u7684\u6700\u4f73\u5f00\u53d1\u5b9e\u8df5\u3002 \u5982\u679c\u60a8\u7b2c\u4e00\u6b21\u5c1d\u8bd5\u5f00\u53d1\u81ea\u5df1\u7684REST API\u3002 \u53ef\u4ee5\u5c1d\u8bd5\u5728\u672c\u6587\u4e2d\u7684REST API\u6700\u4f73\u5b9e\u8df5\u3002<\/p>\n

\u5148\u4ece\u6700\u5c0f\u7684API\u5f00\u59cb\uff0c\u9075\u5faa\u8fd9\u51e0\u4e2a\u5b9e\u8df5\uff0c\u76f8\u4fe1\u60a8\u4f1a\u6210\u5c31\u611f\u6ee1\u6ee1\u3002<\/p>\n

\u540e\u9762\u6211\u4eec\u6709\u4e00\u4e2a\u6301\u7eed\u7684\u7cfb\u5217\u6587\u7ae0\uff0c\u5c55\u793a\u76f8\u5173\u8bed\u8a00\u5f00\u53d1\u5b9e\u8df5\u3002 \u6bd4\u5982\u60a8\u662fC#\u6216\u8005Java\u4e13\u5bb6\uff0c\u4e86\u89e3\u5982\u4f55\u4ee5\u51e0\u79cd\u4e0d\u540c\u7684\u65b9\u5f0f\u4f7f\u7528RESTful API \u3002<\/p>\n

\u6211\u8fd8\u9519\u8fc7\u4e86\u4ec0\u4e48\u5185\u5bb9\u5417\uff1f\u5982\u679c\u60a8\u77e5\u9053\u8fd8\u6709\u66f4\u91cd\u8981\u7684\uff0c\u6b22\u8fce\u5728\u672c\u6587\u5e95\u90e8\u53d1\u8868\u8bc4\u8bba~<\/p>\n

\n

\u539f\u6587\u6765\u81ea\uff1ahttps:\/\/mp.weixin.qq.com\/s?__biz=MjM5NTg2NTU0Ng%3D%3D&chksm=bd5d25af8a2aacb93117b73ba0fdedd528b2a521906285ef8b7dc7acc45b9fad509d57c2cd1b&idx=1&mid=2656596746&scene=0&sn=b7e8ab9e005961f547a244e94c1ea0e8##<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1ahttp:\/\/lrxjmw.cn\/rest-api-practice.html<\/a>\u7f16\u8f91\uff1a\u9004\u589e\u5b9d\uff0c\u5ba1\u6838\u5458\uff1a\u5218\u9044<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u5bfc\u8bfb \u5728\u672c\u6587\u4e2d\uff0c\u6211\u7684\u76ee\u6807\u662f\u5411\u5927\u5bb6\u5c3d\u53ef\u80fd\u8be6\u7ec6\u7684\u89e3\u91caREST API\uff0c\u5305\u62ec\u7406\u8bba\u548c\u5f00\u53d1\u90e8\u5206\u3002\u4ee5\u4fbf\u5927\u5bb6\u80fd\u6e05\u695a\u7684\u4e86\u89e3\u4f55\u65f6 […]<\/p>\n","protected":false},"author":309,"featured_media":94753,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-94752","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/94752","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/309"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=94752"}],"version-history":[{"count":10,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/94752\/revisions"}],"predecessor-version":[{"id":94766,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/94752\/revisions\/94766"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/94753"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=94752"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=94752"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=94752"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}