{"id":441906,"date":"2021-04-17T03:22:21","date_gmt":"2021-04-16T19:22:21","guid":{"rendered":"http:\/\/4563.org\/?p=441906"},"modified":"2021-04-20T02:13:22","modified_gmt":"2021-04-19T18:13:22","slug":"restful-api-%e8%ae%be%e8%ae%a1%e6%9c%80%e4%bd%b3%e5%ae%9e%e8%b7%b5","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=441906","title":{"rendered":"RESTful API \u8bbe\u8ba1\u6700\u4f73\u5b9e\u8df5"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  RESTful API \u8bbe\u8ba1\u6700\u4f73\u5b9e\u8df5               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : liuxing <\/span>  <span><i><\/i> 1<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u672c\u6587\u9996\u53d1\u4e8e \u5218\u661f\u7684\u4e2a\u4eba\u7f51\u7ad9 www.liuxing.io<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2021\/04\/20210419_607dc82fad27d.gif\" alt=\"RESTful API \u8bbe\u8ba1\u6700\u4f73\u5b9e\u8df5\" \/><\/p>\n<h2>\u7b80\u4ecb<\/h2>\n<p>RESTful API \u662f\u76ee\u524d\u6700\u6d41\u884c\u7684 API \u8bbe\u8ba1\u89c4\u8303\uff0c\u5b83\u7528\u4e8e Web \u6570\u636e\u63a5\u53e3\u7684\u8bbe\u8ba1\u3002\u5b83\u5141\u8bb8\u5305\u62ec\u6d4f\u89c8\u5668\u5728\u5185\u7684\u5404\u79cd\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u8fdb\u884c\u901a\u4fe1\u3002\u56e0\u6b64\u6b63\u786e\u662f\u8bbe\u8ba1\u6211\u4eec\u7684 RESTful \u662f\u76f8\u5f53\u91cd\u8981\u7684\uff01\u6211\u4eec\u7684 API \u5fc5\u987b\u5b89\u5168\u3001\u9ad8\u6027\u80fd\u3001\u540c\u65f6\u6613\u4e8e\u4f7f\u7528\u3002<\/p>\n<p>\u5728\u672c\u6587\u6211\u4eec\u5c06\u63a2\u8ba8\u5982\u4f55\u8bbe\u8ba1\u51fa\u6613\u4e8e\u4f7f\u7528\u5e76\u4e14\u5b89\u5168\u5feb\u901f\u7684\u7684 RESTful API \u3002<\/p>\n<p>RESTful API \u5373\u662f\u57fa\u4e8e Rest \u6784\u5efa\u7684 API \u3002\u90a3\u4e48\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u6211\u4eec\u5148\u6765\u770b\u770b REST \u662f\u4ec0\u4e48\uff1f<\/p>\n<p>REST \u4e0e\u6280\u672f\u65e0\u5173\uff0c\u5b83\u4ee3\u8868\u7684\u662f\u4e00\u79cd\u8f6f\u4ef6\u67b6\u6784\u98ce\u683c\uff0cREST \u5b83\u662f Representational State Transfer \u7684\u7b80\u79f0\uff0c\u4e2d\u6587\u7684\u542b\u4e49\u662f: \u8868\u73b0\u5c42\u72b6\u6001\u8f6c\u79fb(\u8f6c\u79fb\uff1a\u901a\u8fc7 HTTP \u52a8\u8bcd\u5b9e\u73b0)\u3002\u5373 URL \u5b9a\u4f4d\u8d44\u6e90\uff0cHTTP \u52a8\u8bcd\u64cd\u4f5c\uff08 GET\uff0cPOST\uff0cPUT\uff0cDELETE \uff09\u63cf\u8ff0\u64cd\u4f5c\u3002<\/p>\n<h2>\u786e\u4fdd\u63a5\u53d7\u5e76\u54cd\u5e94 JSON \u6570\u636e\u683c\u5f0f<\/h2>\n<p>RESTful API \u5e94\u8be5\u63a5\u53d7 JSON \u683c\u5f0f\u7684\u8bf7\u6c42\uff0c\u5e76\u8fd4\u56de\u7684\u54cd\u5e94\u4f53\u4e5f\u5e94\u8be5\u662f JSON \u683c\u5f0f\u7684\u3002JSON \u662f\u4e00\u79cd\u6570\u636e\u4f20\u8f93\u6807\u51c6\uff0c\u4e3b\u6d41\u7f16\u7a0b\u8bed\u8a00\u51e0\u4e4e\u90fd\u80fd\u5f88\u597d\u7684\u652f\u6301\u5b83\u3002\u540c\u65f6\u5728\u6d4f\u89c8\u5668\u4e2d\u6211\u4eec\u7684 JavaScript \u4e5f\u80fd\u5f88\u8f7b\u677e\u65b9\u4fbf\u7684\u64cd\u4f5c\u8fd9\u4e9b\u6570\u636e\u3002\u6240\u4ee5\uff0c\u4ee5 JSON \u683c\u5f0f\u7f16\u5199\u7684 RESTful API \u5177\u6709\u7b80\u5355\u3001\u6613\u8bfb\u3001\u6613\u7528\u7684\u7279\u70b9\u3002<\/p>\n<p>\u4e3a\u4e86\u786e\u4fdd\u5f53\u6211\u4eec\u7684 RESTful API \u670d\u52a1\u4f7f\u7528 JSON \u683c\u5f0f\u54cd\u5e94\uff0c\u6211\u4eec\u5e94\u8be5\u5c06\u5176\u54cd\u5e94\u5934\u7684<code>Content-Type<\/code>\u8bbe\u7f6e\u4e3a<code>application\/json<\/code>\u3002<\/p>\n<p>\u8ba9\u6211\u4eec\u6765\u770b\u4e00\u4e2a\u63a5\u6536 JSON \u6570\u636e\u5e76\u8fd4\u56de JSON \u6570\u636e\u7684 API \u793a\u4f8b\u3002\u672c\u793a\u4f8b\u4f7f\u7528 Node.js \u7684 Express \u6846\u67b6\u3002\u6211\u4eec\u4f7f\u7528\u4e86 body-parser \u4e2d\u95f4\u4ef6\u6765\u89e3\u6790 JSON \u8bf7\u6c42\u4f53\uff0c\u7136\u540e\u4f7f\u7528 <code>res.json<\/code> \u8fd4\u56de\u4f20\u5165\u7684 JSON \u5bf9\u8c61\u3002<\/p>\n<pre><code>const express = require('express'); const bodyParser = require('body-parser');  const app = express();  app.use(bodyParser.json());  app.post('\/', (req, res) =&gt; {   res.json(req.body); });  app.listen(3000, () =&gt; console.log('server started')); <\/code><\/pre>\n<p>\u5728\u672c\u793a\u4f8b\u4e2d <code>bodyParser.json()<\/code> \u5c06 JSON \u8bf7\u6c42\u4f53\u7684\u5b57\u7b26\u89e3\u6790\u4e3a JavaScript \u5bf9\u8c61\uff0c\u7136\u540e\u5c06\u5176\u5206\u914d\u7ed9\u8be5<code>req.body<\/code>\u5bf9\u8c61\u3002<\/p>\n<h2>\u5728 API \u8def\u5f84\u4e2d\u4f7f\u7528\u540d\u8bcd\u4ee3\u66ff\u52a8\u8bcd<\/h2>\n<p>RESTful API \u662f\u9762\u5411\u8d44\u6e90\u7684 API\uff0cHTTP \u52a8\u8bcd\u64cd\u4f5c\uff08 GET\uff0cPOST\uff0cPUT\uff0cDELETE \uff09\u63cf\u8ff0\u64cd\u4f5c\u3002<\/p>\n<p>\u6211\u4eec\u4e0d\u5e94\u8be5\u5728 URL \u8def\u5f84\u4e2d\u4f7f\u7528\u52a8\u8bcd\u3002\u6211\u4eec\u5e94\u8be5\u4f7f\u7528\u8981\u64cd\u4f5c\u7684\u5b9e\u4f53\u7684\u540d\u8bcd\u4f5c\u4e3a\u8def\u5f84\u540d\u3002\u56e0\u4e3a\u6211\u4eec\u7684 HTTP \u8bf7\u6c42\u65b9\u6cd5\u672c\u8eab\u5c31\u662f\u52a8\u8bcd\uff0c\u5c31\u80fd\u63cf\u8ff0\u8981\u8fdb\u884c\u7684\u64cd\u4f5c\uff0c\u5982\u5e38\u89c1\u7684\u65b9\u6cd5\u5305\u62ec GET\uff0cPOST\uff0cPUT \u548c DELETE\uff0c\u8fd9\u4e9b\u8bf7\u6c42\u65b9\u6cd5\u5373\u53ef\u5b8c\u6210 CRUD\u3002<\/p>\n<ul>\n<li>\n<p>GET \u68c0\u7d22\u8d44\u6e90\u3002<\/p>\n<\/li>\n<li>\n<p>POST \u5c06\u65b0\u6570\u636e\u63d0\u4ea4\u5230\u670d\u52a1\u5668\u3002<\/p>\n<\/li>\n<li>\n<p>PUT \u66f4\u65b0\u73b0\u6709\u6570\u636e\u3002<\/p>\n<\/li>\n<li>\n<p>DELETE \u5220\u9664\u6570\u636e\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff0c\u6211\u4eec\u6709\u4e2a\u6587\u7ae0(\/articles\/)\u8d44\u6e90\u3002\u6211\u4eec\u5bf9\u5176\u8fdb\u884c CRUD \u7684 RESTful API \u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 GET <code>\/articles\/<\/code>\u6765\u83b7\u53d6\u6587\u7ae0\u5217\u8868<\/li>\n<li>\u4f7f\u7528 POST <code>\/articles\/ <\/code>\u6dfb\u52a0\u65b0\u6587\u7ae0<\/li>\n<li>\u4f7f\u7528 PUT <code>\/articles\/:id<\/code> \u66f4\u65b0\u7ed9\u5b9a ID \u7684\u6587\u7ae0<\/li>\n<li>\u4f7f\u7528 DELETE<code>\/articles\/:id <\/code> \u5220\u9664\u5177\u6709\u7ed9\u5b9a ID \u7684\u6587\u7ae0<\/li>\n<\/ul>\n<p>\u6211\u4eec\u901a\u8fc7 Express \u6765\u5b9e\u73b0\u4e0a\u9762\u8fd9\u4e2a\u589e\u5220\u6539\u67e5\u7684\u4f8b\u5b50\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre><code>const express = require('express'); const bodyParser = require('body-parser');  const app = express();  app.use(bodyParser.json());  app.get('\/articles', (req, res) =&gt; {   const articles = [];   \/\/ code to retrieve an article...   res.json(articles); });  app.post('\/articles', (req, res) =&gt; {   \/\/ code to add a new article...   res.json(req.body); });  app.put('\/articles\/:id', (req, res) =&gt; {   const { id } = req.params;   \/\/ code to update an article...   res.json(req.body); });  app.delete('\/articles\/:id', (req, res) =&gt; {   const { id } = req.params;   \/\/ code to delete an article...   res.json({ deleted: id }); });  app.listen(3000, () =&gt; console.log('server started')); <\/code><\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86 API \u6765\u64cd\u4f5c\u6587\u7ae0(articles)\u8d44\u6e90\u3002\u5982\u6211\u4eec\u6240\u89c1\uff0cAPI URL \u8def\u5f84\u4e2d\u4f7f\u7528\u7684\u90fd\u662f\u540d\u8bcd\uff0c\u4f5c\u4e3a\u52a8\u8bcd\u7684\u8bf7\u6c42\u65b9\u6cd5\u8bf4\u660e\u4e86 API \u7684\u64cd\u4f5c\u610f\u56fe\u3002<\/p>\n<h2>\u4f7f\u7528\u540d\u8bcd\u590d\u6570<\/h2>\n<p>\u6211\u4eec\u5e94\u8be5\u4f7f\u7528\u590d\u6570\u540d\u8bcd\u6765\u547d\u540d\u96c6\u5408\u3002<\/p>\n<p>\u901a\u5e38\uff0c\u6211\u4eec\u60f3\u8981\u53d6\u5f97\u7684\u6570\u636e\u90fd\u662f\u4e00\u4e2a\u96c6\u5408\uff0c\u800c\u4e0d\u662f\u5355\u4e2a\u9879\u76ee\u3002\u540c\u65f6\u6570\u636e\u5e93\u4e2d\u7684\u8868\u4e5f\u662f\u5177\u6709\u591a\u4e2a\u6761\u76ee\u7684\u3002\u6240\u4ee5\u6211\u4eec\u7684 API \u4e5f\u5e94\u8be5\u4f7f\u7528\u590d\u6570\u540d\u8bcd\uff0c\u8fd9\u6837\u66f4\u5408\u4e4e\u60c5\u7406\u3002<\/p>\n<h2>\u5d4c\u5957\u5206\u5c42\u7684\u8d44\u6e90\u5bf9\u8c61<\/h2>\n<p>\u5728\u5904\u7406\u5d4c\u5957\u8d44\u6e90\u7684 API \u65f6\uff0c\u5e94\u8be5\u5c06\u5d4c\u5957\u8d44\u6e90\u9644\u52a0\u5230\u7236\u8d44\u6e90\u7684\u8def\u5f84\u4e4b\u540e\u3002<\/p>\n<p>\u4f8b\u5982\u4e00\u4e2a\u6587\u7ae0\u6709\u8bc4\u8bba\u5217\u8868\uff0c\u83b7\u53d6\u67d0\u4e2a\u6587\u7ae0\u7684\u8bc4\u8bba\u5217\u8868\u7684 API \u5219\u4e3a:<\/p>\n<pre><code>GET \/articles\/:articleId\/comments <\/code><\/pre>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 express \u6765\u505a\u4e2a\u793a\u8303\uff1a<\/p>\n<pre><code>const express = require('express'); const bodyParser = require('body-parser');  const app = express();  app.use(bodyParser.json());  app.get('\/articles\/:articleId\/comments', (req, res) =&gt; {   const { articleId } = req.params;   const comments = [];   \/\/ code to get comments by articleId   res.json(comments); });   app.listen(3000, () =&gt; console.log('server started')); <\/code><\/pre>\n<h2>\u4f7f\u7528\u6807\u51c6\u7684 http \u72b6\u6001\u7801<\/h2>\n<p>\u4e3a\u4e86\u6d88\u9664 API server \u53d1\u751f\u9519\u8bef\u65f6\u7528\u6237\u7684\u56f0\u60d1\uff0c\u6211\u4eec\u5e94\u8be5\u4f18\u96c5\u5730\u5904\u7406\u9519\u8bef\uff0c\u5e76\u8fd4\u56de\u6307\u793a\u53d1\u751f\u4e86\u5177\u4f53\u9519\u8bef\u7684 HTTP \u54cd\u5e94\u4ee3\u7801\u4ee5\u53ca\u660e\u786e\u7684\u9519\u8bef\u4fe1\u606f\u3002\u8fd9\u53ef\u4ee5\u5f88\u597d\u7684\u4e3a API \u4f7f\u7528\u8005\u63d0\u4f9b\u4e86\u8db3\u591f\u7684\u4fe1\u606f\u6765\u4e86\u89e3\u6240\u53d1\u751f\u7684\u95ee\u9898\u3002<\/p>\n<p>\u5e38\u89c1\u7684\u9519\u8bef HTTP \u72b6\u6001\u4ee3\u7801\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><code>400<\/code> \u9519\u8bef\u7684\u8bf7\u6c42 \u2013 \u8fd9\u610f\u5473\u7740\u5ba2\u6237\u7aef\u8f93\u5165\u9a8c\u8bc1\u5931\u8d25\u3002<\/li>\n<li><code>401<\/code> \u672a\u7ecf\u6388\u6743 &#8211; \u8fd9\u610f\u5473\u7740\u7528\u6237\u65e0\u6743\u8bbf\u95ee\u8d44\u6e90\u3002\u901a\u5e38\u5728\u7528\u6237\u672a\u901a\u8fc7\u8eab\u4efd\u9a8c\u8bc1\u65f6\u8fd4\u56de\u3002<\/li>\n<li><code>403<\/code> \u7981\u6b62\u8bbf\u95ee &#8211; \u8868\u793a\u7528\u6237\u5df2\u901a\u8fc7\u8eab\u4efd\u9a8c\u8bc1\uff0c\u4f46\u4e0d\u5141\u8bb8\u5176\u8bbf\u95ee\u8d44\u6e90\u3002<\/li>\n<li><code>404<\/code> Not Found \u2013 \u8868\u793a\u627e\u4e0d\u5230\u8d44\u6e90\u3002<\/li>\n<li><code>500<\/code> \u5185\u90e8\u670d\u52a1\u5668\u9519\u8bef \u2013 \u8fd9\u662f\u4e00\u822c\u670d\u52a1\u5668\u9519\u8bef\u3002\u5b83\u53ef\u80fd\u4e0d\u5e94\u8be5\u660e\u786e\u5730\u629b\u51fa\u3002<\/li>\n<li><code>502<\/code> \u9519\u8bef\u7684\u7f51\u5173 &#8211; \u8fd9\u8868\u660e\u6765\u81ea\u4e0a\u6e38\u670d\u52a1\u5668\u7684\u65e0\u6548\u54cd\u5e94\u3002<\/li>\n<li><code>503<\/code> \u670d\u52a1\u4e0d\u53ef\u7528 \u2013 \u8fd9\u8868\u793a\u670d\u52a1\u5668\u7aef\u53d1\u751f\u4e86\u610f\u5916\u60c5\u51b5\uff08\u53ef\u80fd\u662f\u670d\u52a1\u5668\u8fc7\u8f7d\uff0c\u7cfb\u7edf\u67d0\u4e9b\u90e8\u5206\u53d1\u751f\u6545\u969c\u7b49\uff09\u3002<\/li>\n<\/ul>\n<p>\u6211\u4eec\u5e94\u8be5\u629b\u51fa\u670d\u52a1\u9519\u8bef\u76f8\u5bf9\u5e94\u7684\u9519\u8bef\u7801\u3002\u4f8b\u5982\uff0c\u5982\u679c\u6211\u4eec\u8981\u62d2\u7edd\u5ba2\u670d\u7aef\u53d1\u8d77\u7684\u8bf7\u6c42\uff0c\u5219\u5e94\u5728 Express API \u4e2d\u8fd4\u56de\u5982\u4e0b\u6240\u793a\u7684 <code>400<\/code> \u54cd\u5e94\uff1a<\/p>\n<pre><code>const express = require('express'); const bodyParser = require('body-parser');  const app = express();  \/\/ existing users const users = [   { email: '[email&#160;protected]' } ]  app.use(bodyParser.json());  app.post('\/users', (req, res) =&gt; {   const { email } = req.body;   const userExists = users.find(u =&gt; u.email === email);   if (userExists) {     return res.status(400).json({ error: 'User already exists' })   }   res.json(req.body); });   app.listen(3000, () =&gt; console.log('server started')); <\/code><\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u7528\u6237\u5c1d\u8bd5\u521b\u5efa\u4e00\u4e2a\u5df2\u7ecf\u5b58\u5728\u7684 user\uff0c\u5c06\u83b7\u5f97 400 \u54cd\u5e94\u72b6\u6001\u4ee3\u7801\uff0c\u5e76\u5e26\u6709\u4e00\u6761<code>'User already exists' <\/code>\u7684\u9519\u8bef\u6d88\u606f\uff0c\u8ba9\u7528\u6237\u77e5\u9053\u8be5\u7528\u6237\u5df2\u7ecf\u5b58\u5728\u3002\u5229\u7528\u8fd9\u4e9b\u4fe1\u606f\uff0c\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u5176\u4ed6 email \u6765\u521b\u5efa\u65b0\u7528\u6237\u3002<\/p>\n<p>\u901a\u5e38\u9519\u8bef\u4ee3\u7801\u9700\u8981\u9644\u5e26\u660e\u786e\u9519\u8bef\u6d88\u606f\uff0c\u4ee5\u4fbf\u7528\u6237\u6709\u8db3\u591f\u7684\u4fe1\u606f\u6765\u4e86\u89e3\u81ea\u5df1\u9047\u5230\u4e86\u4ec0\u4e48\u95ee\u9898\u3002<\/p>\n<p>\u6bcf\u5f53\u6211\u4eec\u7684 API \u672a\u6210\u529f\u8c03\u7528\u65f6\uff0c\u90fd\u5e94\u901a\u8fc7\u53d1\u9001\u660e\u786e\u7684\u9519\u8bef\u4fe1\u606f\u6765\u5e2e\u52a9\u7528\u6237\u91c7\u53d6\u7ea0\u6b63\u63aa\u65bd\u6765\u5b8c\u6210\u64cd\u4f5c\u3002<\/p>\n<h2>\u6dfb\u52a0\u8fc7\u6ee4\uff0c\u6392\u5e8f\u548c\u5206\u9875\u529f\u80fd<\/h2>\n<p>\u901a\u5e38\u6211\u4eec\u7684\u6570\u636e\u90fd\u4f1a\u975e\u5e38\u5e9e\u5927\u3002\u6211\u4eec\u4e0d\u53ef\u80fd\u4e00\u6b21\u5168\u90e8\u8fd4\u56de\uff0c\u8fd9\u4f1a\u975e\u5e38\u6162\u4e5f\u53ef\u80fd\u5bfc\u81f4\u7cfb\u7edf\u5d29\u6e83\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u9700\u8981\u6709\u8fc7\u6ee4\uff0c\u5206\u9875\u6570\u636e\u7684\u65b9\u5f0f\u3002\u8fc7\u6ee4\u548c\u5206\u9875\u90fd\u53ef\u4ee5\u901a\u8fc7\u51cf\u5c11\u6d88\u8017\u670d\u52a1\u5668\u8d44\u6e90\u6765\u63d0\u9ad8\u6027\u80fd\u3002\u8fd9\u4e9b\u529f\u80fd\u76f8\u5f53\u57fa\u7840\u4e14\u91cd\u8981\u3002<\/p>\n<p>\u5206\u9875\u3001\u8fc7\u6ee4\u3001\u6392\u5e8f\u67e5\u8be2\u90fd\u529f\u80fd\u90fd\u5e94\u8be5\u4f7f\u7528\u67e5\u8be2\u53c2\u6570\u6765\u5b9e\u73b0\u3002\u5982\uff1a<\/p>\n<pre><code>\/employees?page=1&amp;pageSize=10&amp;firstName=Xing <\/code><\/pre>\n<p>\u4e0b\u9762\u8fd9\u5c31\u662f\u4e00\u4e2a\u5e26\u6709\u8fc7\u6ee4\u67e5\u8be2\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>const express = require('express'); const bodyParser = require('body-parser');  const app = express();  \/\/ employees data in a database const employees = [   { firstName: 'Jane', lastName: 'Smith', age: 20 },   \/\/...   { firstName: 'John', lastName: 'Smith', age: 30 },   { firstName: 'Mary', lastName: 'Green', age: 50 }, ]  app.use(bodyParser.json());  app.get('\/employees', (req, res) =&gt; {   const { firstName, lastName, age } = req.query;   let results = [...employees];   if (firstName) {     results = results.filter(r =&gt; r.firstName === firstName);   }    if (lastName) {     results = results.filter(r =&gt; r.lastName === lastName);   }    if (age) {     results = results.filter(r =&gt; +r.age === +age);   }   res.json(results); });  app.listen(3000, () =&gt; console.log('server started')); <\/code><\/pre>\n<h2>\u4fdd\u6301\u826f\u597d\u7684\u5b89\u5168\u610f\u8bc6<\/h2>\n<p>\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u4e4b\u95f4\u7684\u5927\u591a\u6570\u901a\u4fe1\u5e94\u8be5\u662f\u79c1\u6709\u7684\u3002\u56e0\u6b64\uff0c\u5fc5\u987b\u4f7f\u7528 SSL\/TLS \u8fdb\u884c\u5b89\u5168\u4fdd\u62a4\u3002\u73b0\u5728\u52a0\u8f7d SSL \u6210\u672c\u662f\u76f8\u5f53\u4f4e\u7684\u3002\u6211\u4eec\u6ca1\u6709\u7406\u7531\u4e0d\u4f7f\u7528\u5b83\u3002<\/p>\n<p>\u540c\u65f6\uff0c\u4e0d\u540c\u7684\u7528\u6237\u5177\u6709\u4e0d\u540c\u7684\u6570\u636e\u8bbf\u95ee\u6743\u9650\u3002\u4f8b\u5982\uff0c\u666e\u901a\u7528\u6237\u4e0d\u5e94\u8be5\u80fd\u591f\u8bbf\u95ee\u5176\u4ed6\u7528\u6237\u7684\u4fe1\u606f\u3002\u4ed6\u4eec\u4e5f\u4e0d\u5e94\u8be5\u80fd\u591f\u8bbf\u95ee\u7ba1\u7406\u5458\u7684\u6570\u636e\u3002<\/p>\n<h2>\u9002\u5f53\u7f13\u5b58\u6570\u636e\u4ee5\u63d0\u9ad8\u6027\u80fd<\/h2>\n<p>\u53ef\u4ee5\u9002\u5f53\u6dfb\u52a0\u7f13\u5b58\u670d\u52a1\uff0c\u4ece\u7f13\u5b58\u4e2d\u8fd4\u56de\u5e38\u7528\u6570\u636e\uff0c\u800c\u4e0d\u662f\u6bcf\u6b21\u90fd\u4ece\u6570\u636e\u5e93\u53bb\u8bfb\u53d6\u3002\u7f13\u5b58\u7684\u597d\u5904\u662f\u53ef\u4ee5\u66f4\u5feb\u5730\u83b7\u53d6\u6570\u636e\uff0c\u4f46\u662f\u4e5f\u8ba9\u6211\u4eec\u83b7\u53d6\u6700\u65b0\u7684\u6570\u636e\u53d8\u5f97\u590d\u6742\u3002\u7f13\u5b58\u65b9\u5f0f\u6709\u5f88\u591a\u5982\uff1aRedis \u3001\u5185\u5b58\u7f13\u5b58( in-memory cache)\u7b49\u7b49\uff0c\u6211\u4eec\u5e94\u8be5\u6839\u636e\u81ea\u5df1\u7684\u5e94\u7528\u5177\u4f53\u60c5\u51b5\u6765\u9009\u62e9\u662f\u4e0d\u662f\u8be5\u7528\u7f13\u5b58\uff0c\u4f7f\u7528\u54ea\u79cd\u7f13\u5b58\u673a\u5236\u3002<\/p>\n<p>\u8fd9\u513f\u6211\u4eec\u6765\u4f7f\u7528 Express \u7684apicache\u4e2d\u95f4\u4ef6\u6765\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u7684\u5185\u5b58\u7f13\u5b58:<\/p>\n<pre><code>const express = require('express'); const bodyParser = require('body-parser'); const apicache = require('apicache'); const app = express(); let cache = apicache.middleware; app.use(cache('5 minutes'));  \/\/ employees data in a database const employees = [   { firstName: 'Jane', lastName: 'Smith', age: 20 },   \/\/...   { firstName: 'John', lastName: 'Smith', age: 30 },   { firstName: 'Mary', lastName: 'Green', age: 50 }, ]  app.use(bodyParser.json());  app.get('\/employees', (req, res) =&gt; {   res.json(employees); });  app.listen(3000, () =&gt; console.log('server started')); <\/code><\/pre>\n<h2>\u7248\u672c\u5316\u6211\u4eec\u7684 API<\/h2>\n<p>\u539f\u5219\u4e0a\u6211\u4eec\u5e94\u8be5\u5c3d\u91cf\u8ba9 API \u907f\u514d\u7834\u574f\u6027\u53d8\u66f4\uff0c\u4fdd\u6301\u5411\u540e\u517c\u5bb9\u3002\u4f46\u662f\u7ecf\u5e38\u6709\u4e9b\u65f6\u5019\u7834\u574f\u6027\u7684\u53d8\u66f4\u662f\u4e0d\u53ef\u907f\u514d\u7684\uff0c\u8fd9\u65f6\u7248\u672c\u5316\u7684 API \u5c31\u6d3e\u4e0a\u7528\u573a\u4e86\u3002\u5f53\u6211\u4eec\u53d1\u5e03\u4e86\u4e0d\u517c\u5bb9\u6216\u91cd\u5927\u66f4\u6539\u53d8\uff0c\u5219\u53ef\u4ee5\u5c06\u5176\u53d1\u5e03\u5728\u65b0\u7248\u672c\u4e2d\u7684 API \u3002<\/p>\n<p>\u6211\u4eec\u901a\u5e38\u901a\u8fc7 URL \u6765\u5b9e\u73b0\u7248\u672c\u5316\uff0c\u53ca\u6dfb\u52a0\u7248\u672c\u53f7\u5728\u6211\u4eec API \u8def\u5f84\u7684\u5f00\u5934\uff0c\u4f8b\u5982\uff1a<code>api.liuxing.io\/v1<\/code> <code>api.liuxing.io\/v2<\/code><\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u5728 express \u5f88\u7b80\u5355\u7684\u5b9e\u73b0\u7248\u672c\u5316\u7684 RESTful API:<\/p>\n<pre><code>const express = require('express'); const bodyParser = require('body-parser'); const app = express();  app.use(bodyParser.json());  app.get('\/v1\/employees', (req, res) =&gt; {   const employees = [];   \/\/ code to get employees   res.json(employees); });  app.get('\/v2\/employees', (req, res) =&gt; {   const employees = [];   \/\/ different code to get employees   res.json(employees); });  app.listen(3000, () =&gt; console.log('server started')); <\/code><\/pre>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u8bbe\u8ba1\u9ad8\u8d28\u91cf RESTful API \u7684\u6700\u91cd\u8981\u7684\u4e00\u70b9\u662f\u9075\u5faa Web \u6807\u51c6\u548c\u7ea6\u5b9a\u4ee5\u4fdd\u6301\u4e00\u81f4\u6027\u3002JSON \u3001SSL\/TLS \u548c HTTP \u72b6\u6001\u4ee3\u7801\u90fd\u662f\u73b0\u4ee3 Web \u7684\u6807\u51c6\u3002\u6027\u80fd\u4e5f\u662f\u91cd\u8981\u7684\u8003\u8651\u56e0\u7d20\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5206\u9875\u3001\u7f13\u5b58\u7b49\u624b\u6bb5\u6765\u63d0\u5347\u6027\u80fd\u3002\u53ef\u7ef4\u62a4\u6027\u53ef\u6269\u5c55\u6027\u4e5f\u662f\u6211\u4eec\u9700\u8981\u8003\u8651\u7684\u3002<\/p>\n<h2>\u66f4\u591a\u63a8\u8350<\/h2>\n<ul>\n<li>Git \u5de5\u4f5c\u6d41\u7a0b\u53ca\u5206\u652f\u7b56\u7565<\/li>\n<\/ul>\n<p>\u672c\u6587\u5b8c<\/p>\n<p>\u6b22\u8fce\u53ef\u4ee5\u5173\u6ce8\u6211\u7684\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u73a9\u800d\u3002\u6709\u6280\u672f\u5e72\u8d27\u4e5f\u6709\u626f\u6de1\u4e71\u8c08<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2021\/04\/675167e2adda46719442223988d2a98atplv-k3u1fbpfcp-zoom-1.image_-1.png\" alt=\"RESTful API \u8bbe\u8ba1\u6700\u4f73\u5b9e\u8df5\" \/><\/p>\n<p>\u5de6\u624b\u4ee3\u7801\u53f3\u624b\u7816\uff0c\u629b\u7816\u5f15\u7389<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>19<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5757112\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : cxe2v <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e8b\u5b9e\u8bc1\u660e\u5b8c\u5168 RESTful \u98ce\u683c\u7684 API \u8bbe\u8ba1\u5c31\u662f\u5757\u7816                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5757113\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : tcsky <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             https:\/\/cloud.google.com\/apis\/design                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5757114\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jmyz0455 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @cxe2v \u8bf7\u95ee\u8fd9\u53e5\u8bdd\u5982\u4f55\u7406\u89e3\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5757115\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : fy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6bd4\u8f83\u7cfb\u7edf\u7684\u5165\u95e8\u6587\u7ae0\uff0c\u4f46\u662f\u8fc7\u4e8e\u8001\u751f\u5e38\u8c08\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5757116\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : gdtdpt <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u501f\u9898\u95ee\u4e00\u4e0b\u5404\u4f4d\u5927\u4f6c\u4eec\uff0c\u5728\u5de5\u4f5c\u4e2d\u7ecf\u5e38\u4f1a\u9047\u5230\u4e00\u4e9b\u975e\u8d44\u6e90\u7c7b\u7684 Api\uff0c\u6bd4\u5982\u5f00\u59cb\u6267\u884c\u67d0\u4e2a\u4efb\u52a1(xxxAction\/execute)\u4e4b\u7c7b\u7684\uff0c\u8fd9\u4e2a\u52a8\u4f5c\u867d\u7136\u53ef\u80fd\u5728\u67d0\u4e9b\u8d44\u6e90\u4e0b\uff0c\u53ef\u4ee5\u7528 \/resource\/:resourceId\/execute \u8fd9\u79cd\u65b9\u5f0f\uff0c\u4f46\u662f\u5982\u679c\u6709\u591a\u79cd\u7c7b\u578b\u7684 action\uff0c\u662f\u4f7f\u7528 \/resource\/:resourceId\/:actionType\/execute \u597d\u8fd8\u662f\u5c06 actionType \u653e\u5230\u53c2\u6570\u4e2d\u597d\uff0c\u6216\u8005\u6709\u6ca1\u6709\u4ec0\u4e48\u66f4\u4f18\u96c5\u7684\u65b9\u5f0f\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5757117\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : kiddyu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @gdtdpt #5 \u8d44\u6e90\u4e0b\u7684\u52a8\u4f5c\u4e00\u822c\u4e0e\u8fd9\u4e2a\u8d44\u6e90\u4e0b\u67d0\u4e2a\u6216\u67d0\u4e9b\u5c5e\u6027\u6709\u5173\uff0c\u53ef\u4ee5\u628a\u8fd9\u4e9b action \u5bf9\u5e94\u5230\u8fd9\u4e9b\u5c5e\u6027\uff0cmethod \u4f7f\u7528 PATCH\uff0c\u7136\u540e\u5c06\u66f4\u591a\u7684\u4fe1\u606f\u653e\u5230\u53c2\u6570\u4e2d                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5757118\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : cxe2v <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @jmyz0455 \u5c31\u662f\u6ca1\u6709\u592a\u9ad8\u7684\u4ef7\u503c\uff0c\u5b9e\u9645\u4e1a\u52a1\u4e2d\u65e0\u6cd5\u4f7f\u7528 RESTful \u8986\u76d6\u5168\u90e8\u60c5\u51b5                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5757119\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : moen <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             PATCH \u53bb\u54ea\u4e86\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5757120\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : h82258652 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8bf7\u6559\u5927\u4f6c\u4eec\u51e0\u4e2a\u95ee\u9898 RESTful \u7684\u5c0f\u767d\u95ee\u9898\u3002<br \/>1 \u3001\u5047\u8bbe\u9875\u9762\u4e0a\u6709\u4e00\u4e2a\u6570\u636e c \u662f\u7531\u9875\u9762\u4e0a\u7684\u53e6\u5916\u4e24\u4e2a\u6570\u636e a \u548c b \u8ba1\u7b97\u51fa\u6765\u7684\uff08\u4f8b\u5982 c = a + b \uff09\uff0c\u90a3\u4e48 API \u4f20\u5165\u548c\u4f20\u51fa\u9700\u8981\u5305\u542b c \u5417\uff1f\u76ee\u524d\u6211\u8fd9\u8fb9\u662f\u4e0d\u4f20\u4e0a\u6765\uff0c\u670d\u52a1\u7aef\u8ba1\u7b97 c \u7684\u503c\uff0c\u7136\u540e\u5b58\u50a8\u5230\u6570\u636e\u5e93\uff0c\u8fd4\u56de\u7684\u65f6\u5019 dto \u5305\u542b c \u5b57\u6bb5\u3002<br \/>2 \u3001\u6811\u72b6\u548c\u5217\u8868\u72b6 API \u540c\u65f6\u51fa\u73b0\u7684\u8bdd\uff0c\u90a3\u4e48\u600e\u4e48\u8bbe\u8ba1\uff1f\u4f8b\u5982\u6709\u4e2a\u996e\u6599\u5206\u7c7b\uff0c\u6700\u591a\u7236\u5b50\u4e24\u7ea7\uff08\u6811\u72b6\u8fd4\u56de\uff09\uff0c\u7136\u540e\u67d0\u4e2a\u573a\u666f\u4e0b\u9700\u8981\u8fd4\u56de\u5168\u90e8\u4e8c\u7ea7\uff08\u5217\u8868\uff09\u3002\u76ee\u524d\u6211\u662f\u5217\u8868\u53eb \/api\/categories\uff0c\u6811\u72b6 \/api\/categories\/tree\uff0c\u4f46\u611f\u89c9\u602a\u602a\u7684\u3002<br \/>3 \u3001HATEOAS \u662f\u4e0d\u662f\u5ffd\u60a0\u4eba\u7684\u6982\u5ff5\u3002\u5b9e\u73b0\u8d77\u6765\u8d39\u529b\u4e14\u4e0d\u5177\u5907\u529f\u80fd\u6027\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5757121\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : huijiewei <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6ca1\u6709\u611f\u89c9\u4ec0\u4e48\u8986\u76d6\u4e0d\u6765\u7684<\/p>\n<p>\u501f\u53e3\u90fd\u4f1a\u627e\uff0cReact \u7406\u89e3\u8d77\u6765\u56f0\u96be\uff0c2021 \u5e74\u4e86\u6211\u8fd8\u5728 $(&#8216;#dom&#8217;).html(&#8216;&lt;span class=&#8221;&#8216; + (isDisabled ? &#8216; disabled&#8217; :&#8217; &#8216;) + &#8216;&#8221;&gt;&#8217; + okle + &#8216;&lt;\/span&gt;&#8217;) \uff1f<\/p>\n<p>\u4f60\u770b\u591a\u76f4\u89c2\uff1f                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5757122\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : huijiewei <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @h82258652 RESTful \u4e00\u5207\u4ee5\u8d44\u6e90\u4e3a\u4e2d\u5fc3\u3002<\/p>\n<p>1. C \u4f20\u4e0d\u4f20\u770b\u4f60\u4e1a\u52a1\uff0c\u6211\u5efa\u8bae\u9700\u8981\u7684\u8d44\u6e90\u90fd\u4f20\u5e76\u8fdb\u884c\u9a8c\u8bc1\uff0c\u4e0d\u7136\u524d\u7aef\u7b97\u51fa\u7684 C \u6709 BUG\uff0c\u7528\u6237\u63d0\u4ea4\u4ee5\u540e\u6570\u636e\u548c\u663e\u793a\u4e0d\u4e00\u6837\u5c82\u4e0d\u662f\u5f88\u5c34\u5c2c<br \/>2. \u6240\u4ee5\u5217\u8868\u548c\u6811\u72b6\u6709\u4ec0\u4e48\u533a\u522b\uff1f\u90fd\u662f\u540c\u4e00\u4e2a\u8d44\u6e90\uff0c\u53ea\u662f\u8868\u73b0\u5f62\u5f0f\u4e0d\u540c\u800c\u5df2\u3002\u660e\u767d\u4e86\u5427<br \/>3. HATEOAS \u53ea\u662f RESTful \u7684\u4e00\u4e2a\u7ec4\u4ef6\uff0c\u96be\u7528\u5c31\u4e0d\u7528\u3002\u603b\u6709\u66f4\u597d\u7684\u5b9e\u8df5                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5757123\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : huijiewei <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @gdtdpt URL PATH \u91cc\u9762\u5efa\u8bae\u53ea\u8868\u73b0\u51fa\u8d44\u6e90\u5373\u53ef                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5757124\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : 3dwelcome <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7528\u7740\u7528\u7740\uff0c\u5230\u6700\u540e\u5c31\u53d8\u6210\u4e86 POST \u4e00\u628a\u68ad\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5757125\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ericls <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u53ea\u9700\u8981\u4e00\u4e2a resource: GraphqlResult.                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5757126\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : cnbattle <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             RESTful API \u5c31\u662f\u8ba9\u540e\u7aef\u7701\u5fc3 \u505a\u4e2a CRUD boy, \u7136\u800c \u524d\u7aef\u5c31\u6709\u70b9\u96be\u53d7\u4e86\uff0c\u9700\u8981\u70b9\u6210\u672c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5757127\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xuanbg <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u540d\u8bcd\u590d\u6570\uff0c\u6211\u5c31\u9047\u5230 knowledge\u2026\u2026\u5c3c\u739b\u4e0d\u5206\u5355\u6570\u590d\u6570\uff0c\u5c31\u79bb\u8c31\u3002\u597d\u4e0d\u5bb9\u6613\u60f3\u660e\u767d\u4e86\u4fee\u6539\u5bc6\u7801\u548c\u91cd\u7f6e\u5bc6\u7801\u7684\u95ee\u9898\uff0c\u4f46\u662f\u5728\u7528\u6237\u7684\u5c01\u7981 \/\u542f\u7528\u4e0a\u9762\u53c8\u9677\u5165\u4e86\u7edd\u5883                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5757128\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yazoox <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @cnbattle \u6b64\u8bdd\u600e\u8bb2\uff1f\u524d\u7aef\u7528 fetch or axios \u4e5f\u8fd8\u662f\u633a\u65b9\u4fbf\u7684\u5427\u3002\u4f60\u8bf4\u7684\u201c\u96be\u53d7\u201d\uff0c\u201c\u6210\u672c\u201d\u6307\u7684\u662f&#8230;?                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5757129\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lychs1998 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             Restful API \u662f\u4e0d\u6ee1\u8db3\u5168\u90e8\u7684\u4e1a\u52a1\u573a\u666f\u9700\u8981\u7684\uff0c\u5e76\u4e0d\u662f\u6240\u6709\u573a\u666f\u90fd\u662f CRUD \u3002\u4f46\u51e1\u5199\u70b9\u590d\u6742\u4e1a\u52a1\u7684\u7cfb\u7edf\uff0c\u5c31\u65e0\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5757130\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : gdtdpt <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @yazoox \u53ef\u80fd\u662f\u540e\u7aef\u5f88\u5bb9\u6613\u627e\u5230\u501f\u53e3\u628a\u5de5\u4f5c\u63a8\u7ed9\u524d\u7aef\u3002<br \/>\u6211\u4eec\u8fd9\u91cc\u6709\u5f88\u591a\u9879\u76ee\u90fd\u662f\u6253\u7740 REST \u7684\u540d\u4e49\u5c06\u6570\u636e\u5b57\u6bb5\u5173\u8054\u52a8\u4f5c\u63a8\u7ed9\u524d\u7aef\u7684\uff0c\u6bd4\u5982\u5fae\u670d\u52a1\u4e0b\u4e24\u4e2a\u670d\u52a1\u95f4 A \u670d\u52a1\u4e1a\u52a1\u8868\u4fdd\u5b58\u4e86 B \u670d\u52a1\u4e1a\u52a1\u8868\u7684 ID \u505a\u4e3a\u903b\u8f91\u4e0a\u7684\u5916\u952e\uff0c\u4f46\u662f\u6570\u636e\u5e93\u4e2d\u56e0\u4e3a\u662f\u4e0d\u540c\u7684\u5e93\u6240\u4ee5\u6ca1\u6709\u7ea6\u675f\u3002\u8fd9\u65f6\u5019\u540e\u7aef\u5c31\u4f1a\u501f\u53e3\u8bf4\u6839\u636e REST \u98ce\u683c\uff0c\u6211\u4ee5\u4e3a\u628a\u6570\u636e\u76f8\u5173\u7684 B \u670d\u52a1\u4e1a\u52a1\u8868\u7684 id \u7ed9\u524d\u7aef\u4e86\uff0c\u81f3\u4e8e id \u5173\u8054\u7684\u6570\u636e\uff0c\u524d\u7aef\u8bf7\u81ea\u5df1\u5230 B \u670d\u52a1\u8bf7\u6c42\u6570\u636e\u56de\u6765\u3002<br \/>\u8fd9\u65f6\u5019\u5c31\u51fa\u73b0\u4e86\u67d0\u4e2a\u9875\u9762\u53ea\u6709\u4e00\u4e2a table\uff0c\u4f46\u662f\u52a0\u8f7d\u8fc7\u7a0b\u4e2d\u4f1a\u53d1\u9001 10 \u591a\u6b21\u8bf7\u6c42\u7684\u60c5\u51b5\uff0c\u800c\u4e14\u52a0\u8f7d\u4e86\u51e0\u6b21\u540e\u5185\u5b58\u7f13\u5b58\u7684\u6570\u636e\u91cf\u5927\u4e86\uff0c\u9875\u9762\u52a0\u8f7d\u7684\u65f6\u5019\u6709\u660e\u663e\u5361\u987f\uff0c\u8fd9\u65f6\u5019\u9886\u5bfc\u6765\u4e00\u53e5\u201c\u9875\u9762\u4e3a\u4ec0\u4e48\u8fd9\u4e48\u5361\uff0c\u524d\u7aef\u600e\u4e48\u5199\u7684\uff0c\u4f18\u5316\u4e00\u4e0b\u201d\uff0c\u8fd9\u65f6\u5019\u5c31\u5f88\u96be\u53d7\uff0c\u660e\u660e\u4e0d\u662f\u524d\u7aef\u7684\u9505\u3002<\/p>\n<p>\u6210\u672c\u5927\u6982\u5c31\u662f\u5b8c\u6210\u4ee5\u4e0a\u6d41\u7a0b\u82b1\u8d39\u7684\u4eba\u529b\u6210\u672c\u5427                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>RESTful API \u8bbe\u8ba1\u6700\u4f73\u5b9e&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/441906"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=441906"}],"version-history":[{"count":1,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/441906\/revisions"}],"predecessor-version":[{"id":441912,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/441906\/revisions\/441912"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=441906"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=441906"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=441906"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}