vscode-restclient icon indicating copy to clipboard operation
vscode-restclient copied to clipboard

Cli runner for the same format

Open tugend opened this issue 6 years ago • 7 comments

Hi. Love the client, it's great. Just what I've been looking for after Postman.

The only thing I really miss, is to have a cli runner of some kind so I can use the same format for automated tests. I'm not saying it should be part of this repo, but could you recommend a tool in the README or possible outfactor the internal engine for reuse - that would really increase the value for me and my team.

tugend avatar Oct 10 '19 13:10 tugend

I'd like that as well, but for testing you would have to define the expected response as well, right?

So the following snippet would be my preferred way of doing this, but I think it's too much for this project. Would be a good idea to move this over to a new project.. AFAIK there is none that does this, but you might want to look into https://taverntesting.github.io/..

# HTTP REST TEST Example

# Variables
@session="ndfu90dsjfosdjf09sdiv9sidßvidsf09vidsß0"
@_csrf="jvidsj0v9weu90fwej90fjw90ejv0e9vjer90jver90jv90e"

# -------------------------------------------
# Post Comment
# -------------------------------------------
POST https://example.com/comments HTTP/1.1
Content-Type: application/json
Cookie: "{{session}}; {{_csrf}}"

{
    "name": "Example Request",
    "value": "1"
}

===

HTTP/1.1 200 OK
Content-Type: application/json

{
	"id": 1234
    "name": "Example Request",
    "value": "1"
}

---
# -------------------------------------------

rwenz3l avatar Oct 30 '19 07:10 rwenz3l

For the sake of readability, i'd prefer something like below to be required. Thanks for the reference, I'll look that up! ^_^

#@assert

HTTP/1.1 200 OK
Content-Type: application/json

{
	"id": 1234
    "name": "Example Request",
    "value": "1"
}

Alternatively we could just use the '@name = hello' attribute to support a separate test file. Something like below or similar, but in a separate file.

Assert @name

HTTP/1.1 200 OK
Content-Type: application/json

{
	"id": 1234
    "name": "Example Request",
    "value": "1"
}

tugend avatar Oct 30 '19 11:10 tugend

It's just that, I really like the readability of the spec. And automated tests ontop is just such an obivious boon. ^_^

Wrt. TavernTesting, I was really hoping for a) something in node instead, and b) something that also integrated with my editor and could be executed manually, like e.g. postmans cli runner and vscode-restclient allows.

tugend avatar Oct 30 '19 11:10 tugend

Since this client is very similar to the one in IDEA (see #627, #692, #267 ), there is https://github.com/restcli/restcli, which intends to be CLI client for IDEA HTTP Client. This brings us back to #627, if features were similar that would mean that people would use the same .http files between IDEA, VSCode, and CLI.

taraspos avatar Oct 22 '20 13:10 taraspos

A bit more reference links: - https://blog.jetbrains.com/phpstorm/2018/04/easier-start-with-the-http-client/ - https://www.jetbrains.com/help/idea/http-client-in-product-code-editor.html - https://youtrack.jetbrains.com/issue/IDEA-239345?_ga=2.61553516.1137828120.1603356975-1132655038.1602585209&p=WI-42002 - https://github.com/restcli/restcli - https://www.jetbrains.com/help/idea/http-response-handling-examples.html#script-var-example

taraspos avatar Oct 22 '20 13:10 taraspos

I stumbled across httpyac. This is a CLI runner for *.http files that also supports NodeJS scripts ( + Intellij). In how far it is identical with RestClient I can not judge. For my use case it is sufficient. https://www.npmjs.com/package/httpyac

jb04021991 avatar Mar 31 '21 17:03 jb04021991

I stumbled across httpyac. This is a CLI runner for *.http files that also supports NodeJS scripts ( + Intellij). In how far it is identical with RestClient I can not judge. For my use case it is sufficient. https://www.npmjs.com/package/httpyac

According to this 'issue' from that project, it is based on this one. Looks like the author had a PR to this, and instead of forking this to get it in, just made a different project to act as the runner, but in the years since this project has been touched, went ahead and just made it a 'superset' of this one. Recommend users just switch over to that one for ongoing support and better features.

StevenSDove avatar Jan 31 '25 23:01 StevenSDove