GithubHelp home page GithubHelp logo

restclientvs's Introduction

Rest Client for Visual Studio

IMPORTANT: This extension can only be installed in Visual Studio 2022 up until version 17.4. In version 17.5 support for .http files were built in to Visual Studio.

Download this extension from the VS Marketplace or get the CI build.


REST Client allows you to send HTTP request and view the response in Visual Studio directly. Based on the popular VS Code extension Rest Client by Huachao Mao

Screenshot

The .http file

Any files with the extension .http or .rest is the entry point to creating HTTP requests.

Here's an example of how to define the requests with variables and code comments.

@hostname = localhost
@port = 8080
@host = {{hostname}}:{{port}}
@contentType = application/json

POST https://{{host}}/authors/create
Content-Type:{{contentType}}

{
    "name": "Joe",
    "permissions": "author"
}

###

# Comments
GET https://{{host}}/authors/

###

GET https://www.bing.com

This is what it looks like in the Blue Theme.

Document

Notice the green play buttons showing up after each URL. Clicking those will fire off the request and display the raw response on the right side of the document.

Tooltip

You can also right-click to find the Send Request command or use the Ctrl+Alt+S keyboard shortcut.

Context Menu

You can set the timeout of the HTTP requests from the Options dialog.

Options

How can I help?

If you enjoy using the extension, please give it a ★★★★★ rating on the Visual Studio Marketplace.

Should you encounter bugs or if you have feature requests, head on over to the GitHub repo to open an issue if one doesn't already exist.

Pull requests are also very welcome, since I can't always get around to fixing all bugs myself. This is a personal passion project, so my time is limited.

Another way to help out is to sponser me on GitHub.

restclientvs's People

Contributors

fretje avatar madskristensen avatar matt3274 avatar sql-mistermagoo avatar taori avatar timheuer avatar tonypatterson avatar varorbc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

restclientvs's Issues

Issue with string parameters with embedded spaces

It appears that string parameters with embedded spaces cause problems for RestClientVS, at least with OData endpoints with string parameters. For example, this URL works in a browser and works in Postman but fails in RESTClientVS:

GET https://localhost:8086/odata/v1/customers(Name='A B C RENTAL CENTER INC')

A 404 is returned. But if the parameter is first URL encoded, like this:

GET https://localhost:8086/odata/v1/customers(Name='A%20B%20C%20RENTAL%20CENTER%20INC')

Then it works.

Response to variable?

Hi,

I've got the impression parsing the response to a variable is not working (yet)?

For example (works in the VSCode extension):

# @name login
POST http://{{host}}/api/Login
Content-Type: application/json

{
  "username": "username",
  "password": "password"
}

###

@token = {{login.response.body.token}}

###

GET http://{{host}}/api/version
token: {{token}}

External file for variables and environments

Is your feature request related to a problem? Please describe.
I'd like to be able to use the REST Client Visual Studio the same way I use it in Visual Studio Code, with variables defined external to the current .http file, and switchable environments.

Describe the solution you'd like
Ideally both extensions would use the same settings files (.vscode/settings.json for nonsensitive settings—probably ..\..\.vscode\settings.json relative to the .sln file), %APPDATA%\Code\User\settings.json for sensitive secret values (or %APPDATA%\Code - Insiders\User\settings.json).

Describe alternatives you've considered
A separate file for the Visual Studio REST Client would be acceptable, but hopefully one that can be committed within the git repo, and one for secrets to be excluded. No switchable environments could work, but that would require some redundancy within the .http to cover the various server and secret permutations.

Additional context
See Environments & Variables in the VSCode REST Client docs.

File POST works in VS Code ext. but not this one.

Describe the bug
POST call to upload a file is working in the VS Code extension but not in this one.
Does not appear to be replacing the @values.

Response in Visual Studio Pro 2022 (64-bit) v17.1.5 is:
"An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set."

To Reproduce
@hostname = localhost
@PORT = 44388
@host = {{hostname}}:{{port}}
@baseurl = https://{{host}}

@boundary = ----demoBoundary
@contentType = multipart/form-data; boundary={{boundary}}

POST {{baseurl}}/sendfile HTTP/1.1
Content-Type: {{contentType}}

--{{boundary}}
Content-Disposition: form-data; name="file"; filename="jellyfish.jpg"
Content-Type: application/octet-stream

< ./files/pexels-cristian-muduc-10027304.jpg
--{{boundary}}--

Expected behavior
The "[FromForm(Name = "file")] IFormFile file" is seen by the endpoint. It is valid when sent from VS Code, but null when sent by this extension.

Very interested to see the inclusion of Authentication

Is your feature request related to a problem? Please describe.
Not too many Apis these day are open, they require some sort of auth. I find in my line of work Bearer tokens (OAuth/OIDC) flow to be the most useful.

Describe the solution you'd like
Initial implementation, just support for the Authentication: Bearer xxx header would be good, later the inclusion of fetching a token from Azure B2C or similar.

Describe alternatives you've considered
None really, as Auth is done in very specific ways these days.

Additional context
Similar features exist in REST Client for VSCode and the spec it has would be good to emulate. Can this be a colab with that project maybe?

README.md?

This looks really cool. Mind doing a README.md with maybe any screenshots?

Unable to install extension for VS 2019 Community

Describe the bug
The Visual Studio 2019 Extension explorer does not find this version of REST Client. Instead it points to AdrianDev's version that does not work after installation.

To Reproduce
So, I downloaded the .vsix from Github and installed directly using the VSIXInstaller.exe in an Admin shell:

VSIXInstaller.exe /skuName:Community /skuVersion:16.11.18 c:\tmp\RestClientVS.vsix

A dialog appears that "Install failed". It references a log file. Both are attached.

Expected behavior
Successful install so that I can use RESTClient from VS 2019 Community instead of using VS Code.

installFailed
dd_VSIXInstaller_20220905172010_04f4.log

Indicate request activity in the text editor

Is your feature request related to a problem? Please describe.
I did not immediately notice that a request was in progress as the green arrow doesn't change.

Describe the solution you'd like
When the green arrow/play button is clicked, it should change to (e.g. hourglass) indicate the request is in progress, and change back to an arrow when the request is complete.

Describe alternatives you've considered
None - the alternative is already implemented - status bar text - which is good, but not as obvious for me.

Additional context
I have created a branch that implements this - and below if a GIF of how it looks in use.
If you like the idea, I can submit a PR and you can tell me all the things I got wrong 😁👍🏼

This GIF shows two requests:

  • the first one will fail as there is nothing listening on the endpoint - the green arrow changes to a green hourglass when it is clicked. The green hourglass is replaced by a red arrow (to indicate the request failed) upon completion.
  • the second request is a valid request, so you only briefly see the hourglass and upon completion, the green arrow is back to indicate success.

The hourglass is a bit meh and the alignment is wrong, but that can be fixed.

Show progress in rest client

The implementation I went for adds a couple of bool status fields to the Request that the Play Button adornment uses to determine the correct icon. When the button is clicked, it resets the status fields to indicate it is active before triggering the Send Request Command.

The Send Request Command calls a method on the Request to confirm completion and passes it the result status (based on IsSuccessStatusCode)

There is some fragility in the result colouring because the Request will be re-created by an edit - not sure that matters much?

Top-level array results in JSON parsing error

Describe the bug
When the API returns an array as the top level (not an object), I get the following error:

Date: Tue, 26 Apr 2022 12:58:51 GMT
Server: Kestrel

** RestClientVS : Error parsing JSON ( Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1. ), raw content follows. **

[]

To Reproduce
Steps to reproduce the behavior:

  1. Create an API method that returns an empty array
  2. Call it from an HTTP file
  3. See error

Expected behavior
It should parse the array.

Add Missing Rest PATCH method

Describe the bug
The REST PATCH method is missing

To Reproduce

Trying to write a .http test method as follows

###
PATCH {{host}}/{{organisation_resource_name}}/{{organisation_id}}
Content-Type: application/json-patch+json; ext=jsonpatch
Accept:  application/json-patch+json; ext=jsonpatch
[
  {
    "op": "replace",
    "value": "Fantastic org name",
    "path": "name"
  }
]
###

Expected behavior
Should be able to execute a PATCH method

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context

From what I can ascertain from the code the Method is missing from the IntellisenseCatalog.cs

below I have added what I think the option should be

 public static readonly IDictionary<string, string> HttpMethods = new Dictionary<string, string>()
        {
            {"GET",     "The GET method is used to retrieve information from the given server using a given URI.Requests using GET should only retrieve data and should have no other effect on the data."},
            {"HEAD",    "Same as GET, but transfers the status line and header section only."},
            {"POST",    "A POST request is used to send data to the server, for example, customer information, file upload, etc. using HTML forms"},
            {"PUT",     "Replaces all current representations of the target resource with the uploaded content."},
            {"DELETE",  "Removes all current representations of the target resource given by a URI."},
            {"TRACE",   "Performs a message loop-back test along the path to the target resource."},
            {"OPTIONS",  "Describes the communication options for the target resource."},
            {"PATCH", "Used to modify the values of the resource properties." }
        };

Support for .rest extension

I have always used .rest extension in VSC and it would be great if this extension was also supported in VS, so I don't have to rename everything.

Inline version of HTTP is not supported

Description

I tried to use an http file I had in a project of mine.
The http test file is the following:

### test
GET http://dummy.restapiexample.com/api/v1/employee/1 HTTP/1.1
Content-Type:application/json
  • The VSCode extension supports the HTTP/1.1 at the end of the URL and the request produces a correct answer (some json data).
  • RestClientVS does not understand HTTP/1.1 and responds:
HTTP/1.1 404 Not Found
  • Intercepting with Fiddler the RestClientVS request shows the wrong request URL:
GET /Gates/Config%20HTTP/1.1 HTTP/1.1

Steps to reproduce

  1. Open the http file containing just the lines above
  2. Test on VSCode and on VS

Expected behavior:
RestClientVS should behave exactly the same ad the VSCode extension

Actual behavior:
A HTTP 404 error is produced

UI Rework

Is your feature request related to a problem? Please describe.
I looked at the VSCode rest clients and thought they structured the data more nicely. I was wondering if you are open to a rework?

Describe the solution you'd like
I'd copy this UI pretty much, because it seems amazing. (https://marketplace.visualstudio.com/items?itemName=rangav.vscode-thunder-client)

Describe alternatives you've considered
I think any work invested into UI could be a great benefit.

Additional context
I would be willing to do the work, though it may take some time depending on how busy i am with my work

Keyboard commands such as Ctrl-C (Copy) not working in ResponseControl

Describe the bug
The ResponseControl does not allow keyboard commands as it does not accept focus.
This means you have to select text with your mouse, then right click and select copy to use the clipboard.

To Reproduce
Steps to reproduce the behavior:

  1. Run any http request
  2. Select some text in the results margin
  3. Press Ctrl/Cmd+C (Copy to clipboard) on your keyboard
  4. Try to paste - the selected text has not been copied

Expected behavior
You should be able to copy text using standard shortcuts.

Screenshots
N/A

Additional context
I am submitting a one line PR for this 😄

Response Result pass to Variable Not Work on Visual Studio 2022

Describe the bug
The response body result (as show below) doesn't work in Visual Studio 2022!! only work on VSCode

@hostname = localhost
@PORT = 7056
@host = {{hostname}}:{{port}}
@contentType = application/json

@name authPasswordRequest

POST https://{{host}}/api/Authentication/Login
Content-Type: {{contentType}}

{
"username": "[email protected]",
"password": "abc123",
"isClient": true
}

Get User Profile Request:

@accesstoken = {{authPasswordRequest.response.body.$.data.token}}

Get test

GET https://{{host}}/api/Authentication/TestParam?param={{accessToken}} HTTP/1.1

Get Client

GET https://{{host}}/api/Client?companyId=2&skip=0&take=5 HTTP/1.1
Accept: {{contentType}}
Authorization: Bearer {{accessToken}}

To Reproduce
Steps to reproduce the behavior:
run the above code

Expected behavior
variable accessToken can't get the response body result

Screenshots
If applicable, add screenshots to help explain your problem.
image
Capture

JWT Variable Storing and Reuse

Allow users to call an endpoint to grab a JWT, store it in a variable, then use it when invoking other endpoints.

What you came up with is brilliant. However, not everyone uses anonymous endpoints. And without having the ability to grab, store, and reuse a JWT, it doesn't provide me an advantage over just using Postman.

Cancellation support using Stop

Is your feature request related to a problem? Please describe.
I have noticed that when you can stop a request by clicking the green play button. You get a no-entrance sign icon shown. Indicating that you stopped the request. This is the same as hitting the X (Stop) icon in the browser.

What I also noticed that this does not Cancel the HttpRequest. Initially you get a 408 showen, see screenshot below.

image

But a few seconds later you still get the wheatherfocast json response shown.

image

My endport support Cancellation using a CancellationToken.

app.MapGet("/weatherforecast", async (CancellationToken cancellationToken) => {

    await Task.Delay(5000, cancellationToken); // Simulate some slow database access

    var forecast = Enumerable.Range(1, 5).Select(index =>
        new WeatherForecast
        (
            DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
            Random.Shared.Next(-20, 55),
            summaries[Random.Shared.Next(summaries.Length)]
        ))
        .ToArray();
    return forecast;
})
.WithName("GetWeatherForecast")
.WithOpenApi();

If I Stop the GET request in a browser. In edge using the X button located left to the Home button the request is cancelled.

image

Describe the solution you'd like
Cancel the HttpClient request by parsing the Token of a CancellationTokenSource. Call Cancel on this CancellationTokenSource. This will cancel the request.

How does this extension relate to VS17.5 feature for .http/.rest files?

I have used the VS Code extension Rest Client by Huachao Mao and was looking for the VS Studio alternative, which is this extension. And now I found that in VS17.5 this is build in: https://devblogs.microsoft.com/visualstudio/visual-studio-2022-17-5-released/#api

Are these VS efforts at all related?
The format of the .http file appears to be similar; is there a common specification that can be followed to enable interoperability with the VS Code extension, the VS Extension and VS itself?

Enable the ability to view the request as part of the response

Is your feature request related to a problem? Please describe.
The VSCode extension this is based on allows you to log both the request and response received

Describe the solution you'd like
Be able to see the request that was sent

Describe alternatives you've considered
N/A

Additional context
The setting in the VS Code version is rest-client.previewOption
image

Newlines in application/x-www-form-urlencoded body should not be sent in request

When building a request body with ContentType application/x-www-form-urlencoded, I usually place each parameter on a new line for readability, like so:
param1=value1
&param2=value2
&param3=value3
...

This works just fine in RESTClient for VSCode, but here, it sends the newlines as part of the parameter values, leading to 400 (Bad Request) errors when POST-ing to the server, as it does not expect newlines.

Cookie hasn't been sent in the request

Describe the bug
Cookie header is not included in the request

To Reproduce
Steps to reproduce the behavior:

  1. Launch Fiddler
  2. Send a request with Cookie set
  3. Review the request in Fiddler

Expected behavior
Cookie should be sent along with all other request headers

The input does not contain any JSON tokens Calling local Azure Function

Describe the bug

When running a POST in debug of an azure function. the body of the request is empty so an error:"The input does not contain any JSON tokens" is raised.

To Reproduce
the code:
POST http://localhost:7078/api/CreateNoProjectSite Content-Type: application/json { "SiteDisplayName":"NewTeamSite1", "SiteName":"NewTeamSite15", "SiteDescription":"NewTeamSite15", "SiteMembers":["[email protected]"], "SiteOwners":["[email protected]","[email protected]"], "Sitetype":1 }
runs fine in other Rest client. but fails to send the body from a .HTTP or .REST file in same VS

Expected behavior
Run like a REST client

Screenshots
image

Thank you

Not sure if this is a VS bug really...

Describe the bug
If the .http file is part of a solution then you cannot copy from the ResponseControl TextBox using the keyboard Ctrl+C shortcut.

To Reproduce
Steps to reproduce the behavior:

  1. Open any Solution in VS
  2. Use File...Open to open an .http file
  3. Run one of the REST calls in the .http file
  4. Select some text in the Results text area and use the keyboard shortcut to copy the text
  5. Paste into the text editor pane - it will paste the text you copied.
  6. Now (you can leave the .http file open) add the .http to the Solution using Add..Existing Item
  7. Select some different text in the results pane and use the keyboard shortcut to copy the text
  8. Paste into the text editor pane - it will not paste anything - nothing was copied to the clipboard.

Expected behavior
Using keyboard shortcuts should work whether a file is part of a Solution or not.

Screenshots
When the file is not part of the solution, keyboard shortcuts work
image

When the file is part of the solution, keyboard shortcuts do not work
image

Additional context
I logged this here so it can be tracked, but I suspect it must be a VS issue, so I will log it there as well and cross-reference.

Add a .http file template to Add New Item window.

Is your feature request related to a problem? Please describe.
There is no .http file template for creating a new .http file. Currently one must create a new Empty file or perhaps a regular text file, and rename it to [something].http.

Describe the solution you'd like
Add a .http file template to the selections in the Add New Item dialogue window.

Describe alternatives you've considered
Manual alternatives are mentioned above.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.