Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smart selection of request boundaries if no manual selection is made #666

Closed
waldyrious opened this issue Aug 17, 2020 · 2 comments
Closed

Comments

@waldyrious
Copy link

It is a bit cumbersome to manually select an entire request to be able to right-click and, for example, copy it as a curl command. I would like the extension to automatically determine a request's boundaries when no selection is made, so I could simply right-click anywhere within a request and perform actions with it. This issue is similar to #644/#645, but the proposed behavior is the opposite: generating code for a single request (the one around the current cursor position).

The auto-detection could be done by simple heuristics, such as reading the request body until the first blank line (as is currently done to separate the headers from the body); or alternatively, using something more elaborate such as reading until the next line that starts with an all-caps HTTP verb followed by an URL.

Of course, these heuristics would fail in some edge cases, but I'd argue that even so it would still be an improvement over the current behavior, since at the moment any requests under the first one get appended as data, which is never what one would want/expect. For example, given the following .http file:

# Example with JSON data
POST https://api.example.com/address
Content-Type: application/json

{
  "foo": "bar",
  "baz": "qux"
}

# Example with query parameters
GET https://example.com/comments
    ?page=2
    &pageSize=10

# Example with form-urlencoded data
POST https://api.example.com/login
Content-Type: application/x-www-form-urlencoded

name=foo
&password=bar

...right-clicking on the "foo": "bar" line and generating a cURL command line yields the following:

curl --request POST \
  --url https://api.example.com/address \
  --header 'content-type: application/json' \
  --header 'user-agent: vscode-restclient' \
  --data '{"foo": "bar","baz": "qux"}GET https://example.com/comments?page=2&pageSize=10POST https://api.example.com/loginContent-Type: application/x-www-form-urlencodedname=foo&password=bar'

while I would expect it to be instead:

curl --request POST \
  --url https://api.example.com/address \
  --header 'content-type: application/json' \
  --header 'user-agent: vscode-restclient' \
  --data '{"foo": "bar","baz": "qux"}
@Huachao
Copy link
Owner

Huachao commented Aug 18, 2020

@waldyrious you need to add request delimiter ### between requests to mark request boundary if you wish to put multiple requests in the same http file as following:

# Example with JSON data
POST https://api.example.com/address
Content-Type: application/json

{
  "foo": "bar",
  "baz": "qux"
}

###
# Example with query parameters
GET https://example.com/comments
    ?page=2
    &pageSize=10

###
# Example with form-urlencoded data
POST https://api.example.com/login
Content-Type: application/x-www-form-urlencoded

name=foo
&password=bar

@Huachao Huachao closed this as completed Aug 18, 2020
@waldyrious
Copy link
Author

Oh, right! 🤦 I don't know how I missed that in the documentation, it's right there :) sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants