• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

cloudhead/http-console: simple, intuitive HTTP REPL — Speak HTTP like a local.

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

cloudhead/http-console

开源软件地址:

https://github.com/cloudhead/http-console

开源编程语言:

JavaScript 100.0%

开源软件介绍:

http-console

Speak HTTP like a local

Talking to an HTTP server with curl can be fun, but most of the time it's a PITA.

http-console is a simple and intuitive interface for speaking the HTTP protocol.

PS: HTTP has never been this much fun.

synopsis

http-console

installation

http-console was written for node, so make sure you have that installed first. Then you need npm, node's package manager.

Once you're all set, to install globally, run:

$ npm install http-console -g

It'll download the dependencies, and install the command-line tool in /usr/local/bin (you may need to make use of sudo or equivalent to gain access).

Installing the bleeding edge

The latest release will often be available on npm as http-console@latest, so you can run:

$ npm install http-console@latest

Alternatively, you can download a tarball of this repo, or clone it. Just make sure you have the latest version of node.

introduction

Let's assume we have a CouchDB instance running locally.

connecting

To connect, we run http-console, passing it the server host and port as such:

$ http-console 127.0.0.1:5984 

navigating

Once connected, we should see the http prompt:

http://127.0.0.1:5984/>

server navigation is similar to directory navigation, except a little simpler:

http://127.0.0.1:5984/> /logs
http://127.0.0.1:5984/logs> /46
http://127.0.0.1:5984/logs/46> ..
http://127.0.0.1:5984/logs> ..
http://127.0.0.1:5984/>

requesting

HTTP requests are issued with the HTTP verbs GET, PUT, POST, HEAD and DELETE, and a relative path:

http://127.0.0.1:5984/> GET /
HTTP/1.1 200 OK
Date: Mon, 31 May 2010 04:43:39 GMT
Content-Length: 41

{
    couchdb: "Welcome",
    version: "0.11.0"
}

http://127.0.0.1:5984/> GET /bob
HTTP/1.1 404 Not Found
Date: Mon, 31 May 2010 04:45:32 GMT
Content-Length: 44

{
    error: "not_found",
    reason: "no_db_file"
}

When issuing POST and PUT commands, we have the opportunity to send data too:

http://127.0.0.1:5984/> /rabbits
http://127.0.0.1:5984/rabbits> POST
... {"name":"Roger"}

HTTP/1.1 201 Created
Location: http://127.0.0.1/rabbits/2fd9db055885e6982462a10e54003127
Date: Mon, 31 May 2010 05:09:15 GMT
Content-Length: 95

{
    ok: true,
    id: "2fd9db055885e6982462a10e54003127",
    rev: "1-0c3db91854f26486d1c3922f1a651d86"
}

Make sure you have your Content-Type header set properly, if the API requires it. More in the section below.

Note that if you're trying to POST to a form handler, you'll most probably want to send data in multipart/form-data format, such as name=roger&hair=black. http-console sends your POST/PUT data as is, so make sure you've got the format right, and the appropriate Content-Type header.

setting headers

Sometimes, it's useful to set HTTP headers:

http://127.0.0.1:5984/> Accept: application/json
http://127.0.0.1:5984/> X-Lodge: black

These headers are sent with all requests in this session. To see all active headers, run the .headers command:

http://127.0.0.1:5984/> .headers
Accept: application/json
X-Lodge: black

Removing headers is just as easy:

http://127.0.0.1:5984/> Accept:
http://127.0.0.1:5984/> .headers
X-Lodge: black

Because JSON is such a common data format, http-console has a way to automatically set the Content-Type header to application/json. Just pass the --json option when starting http-console, or run the .json command:

$ http-console 127.0.0.1:5984 --json
http://127.0.0.1:5984/> .headers
Accept: */*
Content-Type: application/json

cookies

You can enable cookie tracking with the --cookies option flag. To see what cookies are stored, use the .cookies command.

SSL

To enable SSL, pass the --ssl flag, or specify the address with https.

quitting

http://127.0.0.1:5984/> .q

nuff' said.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
candrews/HttpResponseCache发布时间:2022-06-17
下一篇:
GSA/https: The HTTPS-Only Standard for federal domains (M-15-13), and implementa ...发布时间:2022-06-17
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap