在Mac OS下使用Node.js的简单教程(3)

$ http-console :8000 The "sys" module is now called "util". It should have a similar interface. > http-console 0.6.1 > Welcome, enter .help if you're lost. > Connecting to 127.0.0.1 on port 8000. :8000/> \json :8000/>


访问 REST 服务

在 http-console 中,要执行 GET 请求只需要输入 GET /bookmarks 即可:
 

:8000/> GET /bookmarks HTTP/1.1 200 OK Date: Sun, 01 Apr 2012 17:23:27 GMT Server: journey/0.4.0 Content-Type: application/json;charset=utf-8 Content-Length: 16 Connection: keep-alive { bookmarks: [] }


你也可以使用 JSON 的片段来执行 POST 请求:
 

:8000/> POST /bookmarks ... { "url": "http://nodejs.org" } HTTP/1.1 200 OK Date: Thu, 05 Apr 2012 11:45:55 GMT Server: journey/0.4.0 Content-Type: application/json;charset=utf-8 Content-Length: 91 Connection: keep-alive { bookmark: { _id: 'WD-G-1', resource: 'Bookmark', url: 'http://nodejs.org' } }


然后再次执行 GET 请求,你就可以看到新插入的数据了:
 

:8000/> GET /bookmarks HTTP/1.1 200 OK Date: Sun, 01 Apr 2012 17:23:27 GMT Server: journey/0.4.0 Content-Type: application/json;charset=utf-8 Content-Length: 16 Connection: keep-alive { bookmarks: [ { _rev: '1-cfced13a45a068e95daa04beff562360', _id: 'WD-G-1', resource: 'Bookmark', url: 'http://nodejs.org' } ] }

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgdjsf.html