restful全部命令_RESTful HTTP服务的命令行REPL

restful全部命令

restful全部命令

HTTP REPL

My that's a lot of acronyms. REPL means "Read Evaluate Print Loop." You know how you can run "python" and then just type 2+2 and get answer? That's a type of REPL.

我的缩写很多。 REPL的意思是“读取评估打印循环”。 您知道如何运行“ python”,然后键入2 + 2并获得答案吗? 那是REPL的一种。

The ASP.NET Core team is building a REPL that lets you explore and interact with your RESTful services. Ideally your services will have Swagger/OpenAPI available that describes the service. Right now this Http-REPL is just being developed and they're aiming to release it as a .NET Core Global Tool in .NET Core 2.2.

ASP.NET Core团队正在构建REPL,使您可以探索RESTful服务并与之交互。 理想情况下,您的服务应具有描述该服务的Swagger / OpenAPI 。 目前,此Http-REPL刚刚被开发,他们的目标是将其作为.NET Core 2.2中的.NET Core全局工具发布。

You can install global tools like this:

您可以这样安装全局工具:

dotnet tool install -g nyancat

Then you can run "nyancat." Get a list of installed tools like this:

然后,您可以运行“ nyancat”。 获取以下已安装工具的列表:

C:\Users\scott> dotnet tool list -g
Package Id                 Version                   Commands
--------------------------------------------------------------------
altcover.global            3.5.560                   altcover
dotnet-depends             0.1.0                     dotnet-depends
dotnet-httprepl            2.2.0-preview3-35304      dotnet-httprepl
dotnet-outdated            2.0.0                     dotnet-outdated
dotnet-search              1.0.0                     dotnet-search
dotnet-serve               1.0.0                     dotnet-serve
git-status-cli             1.0.0                     git-status
github-issues-cli          1.0.0                     ghi
nukeeper                   0.7.2                     NuKeeper
nyancat                    1.0.0                     nyancat
project2015to2017.cli      1.8.1                     csproj-to-2017

For the HTTP-REPL, since it's not yet released you have to point the Tool Feed to a daily build location, so do this:

对于HTTP-REPL,由于尚未发布,因此您必须将工具Feed指向每日构建位置,因此请执行以下操作:

dotnet tool install -g --version 2.2.0-* --add-source https://dotnet.myget.org/F/dotnet-core/api/v3/index.json dotnet-httprepl

Then run it with "dotnet httprepl." I'd like another name? What do you think? RESTy? POSTr? API Test? API View?

然后使用“ dotnet httprepl”运行它。 我想要别的名字吗? 你怎么看? 休息吗海报? API测试? API视图?

Here's an example run where I start up a Web API.

这是我启动Web API的示例运行。

C:\SwaggerApp> dotnet httprepl
(Disconnected)~ set base http://localhost:65369
Using swagger metadata from http://localhost:65369/swagger/v1/swagger.json

http://localhost:65369/~ dir
.        []
People   [get|post]
Values   [get|post]

http://localhost:65369/~ cd People
/People    [get|post]

http://localhost:65369/People~ dir
.      [get|post]
..     []
{id}   [get]

http://localhost:65369/People~ get
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Date: Wed, 26 Sep 2018 20:25:37 GMT
Server: Kestrel
Transfer-Encoding: chunked

[
  {
    "id": 1,
    "name": "Scott Hunter"
  },
  {
    "id": 0,
    "name": "Scott Hanselman"
  },
  {
    "id": 2,
    "name": "Scott Guthrie"
  }
]

Take a moment and read that. It can be a little confusing. It's not HTTPie, it's not Curl, but it's also not PostMan. it's something that you run and stay running if you're a command line person and enjoy that space. It's as if you "cd (change directory)" and "mount" a disk into your Web API.

花一点时间阅读。 可能会有些混乱。 它不是HTTPie ,不是Curl,但是它也不是PostMan。 如果您是命令行用户并且喜欢这个空间,那么您可以运行并保持运行。 就像您将cd(更改目录)并将磁盘“装入” Web API一样。

You can use all the HTTP Verbs, and when POSTing you can set a default text editor and it will launch the editor with the JSON written for you! Give it a try!

您可以使用所有HTTP动词,并且在POST时可以设置默认的文本编辑器,它将使用为您编写的JSON启动编辑器! 试一试!

A few gotchas/known issues:

一些陷阱/已知问题:

  • You'll want to set a default Content-Type Header for your session. I think this should be default.

    您需要为会话设置默认的Content-Type标头。 我认为这应该是默认设置。
    • set header Content-Type application/json

      设置标头Content-Type application / json

  • If the HTTP REPL doesn't automatically detect your Swagger/OpenAPI endpoint, you'll need to set it manually:

    如果HTTP REPL无法自动检测到您的Swagger / OpenAPI端点,则需要手动进行设置:
    • set base https://yourapi/api/v1/

      设置基础https:// yourapi / api / v1 /

    • set swagger https://yourapi/swagger.json

      设置摇摇欲坠https://yourapi/swagger.json

  • I haven't figure out how to get it to use VS Code as its default editor. Likely because "code.exe" isn't a thing. (It uses a batch .cmd file, which the HTTP REPL would need to special case). For now, use an editor that's an EXE and point the HTTP REPL like this:

    我还没有弄清楚如何使用VS Code作为其默认编辑器。 可能是因为“ code.exe”不是问题。 (它使用一个批处理.cmd文件,HTTP REPL在特殊情况下需要使用该文件)。 现在,使用作为EXE的编辑器,并指向HTTP REPL,如下所示:
    • pref set editor.command.default 'c:\notepad2.exe'

      预设置editor.command.default'c:\ notepad2.exe'

I'm really enjoy this idea. I'm curious how you find it and how you'd see it being used. Sound off in the comments.

我真的很喜欢这个主意。 我很好奇您如何找到它以及如何使用它。 在评论中听起来不错。

翻译自: https://www.hanselman.com/blog/a-commandline-repl-for-restful-http-services

restful全部命令

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值