AnWeber / vscode-httpyac

Quickly and easily send REST, Soap, GraphQL, GRPC, MQTT and WebSocket requests directly within Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=anweber.vscode-httpyac
MIT License
237 stars 20 forks source link

use axios instead of got for sending request #179

Closed Gxmadix closed 1 year ago

Gxmadix commented 1 year ago

Is it possible to use httpyac, with another library than got, got does not support body on get requests, but axios does.

This make these kinds of requests impossible to perform, it is not a good choice to pass the data in query params neither it is to make it a post request, a QUERY method is in study, but we are not there yet, so in the meantime a good workaround is to keep using libraries that support body with get method.

request

### find person list
# @name findPersonList
# @ref authSignin
GET {{Endpoint}}
Authorization: Bearer {{ authSignin.token }}

{
  "email": ["test@dd.www", "Drake.Feest97@gmail.com"]
}

Error message:

RequestError: TheGETmethod cannot be used with a body at Gk._destroy

Gxmadix commented 1 year ago

Finally, I found a way to make this work with got, by passing this option allowGetBody.

"httpyac.requestGotOptions": {
    "allowGetBody": true
  }

I am keeping this issue open, to let you decide guys if that's still worth keeping in mind as an option.

AnWeber commented 1 year ago

The decision for got was deliberate. My POC had still used axios. The main reason was that got also supports HTTP/2 and I wanted to be as close as possible to the actual browser call. But I left it open to implement a axios plugin on your own. You would just to implement httpClientProvider which wraps all calls to got. But I didn't implement the interface cleanly, because in some places I still use the Got Request Options myself (like in digestVariableProvider). I will put this on my bucket list for improvements.

I did not know the setting and I add it. Even if I would rather not use it myself on the server side.

Kaarel commented 1 year ago

https://github.com/sindresorhus/got/blob/main/documentation/2-options.md#allowgetbody

"However, the HTTP/2 specification says: An HTTP GET request includes request header fields and no payload body"

Doesn't sound like GET requests were designed to do this...

AnWeber commented 1 year ago

@Kaarel I agree with you that it is not part of the specification, and for that reason I will not use it myself in any way. It is not worth the trouble. However, it shouldn't be a problem to allow it in for use in httpyac. Or do you know constellations where this can become a problem ?

Kaarel commented 1 year ago

Nah, just noticed this thread and started wondering about bodies with GET requests :)

Gxmadix commented 1 year ago

@Kaarel, in fact in the front side, it is much easier to work with a get request when handling a request like a search, principally for caching, and on the back side I am much more comfortable with a get since the request is not changing any database or server state, last time I honestly searched some hours on this topic, and I can say that the number of people not seeing any problem with using a body in get is increasing with years, there will be some old servers that will ignore the body on gets, but the risk is still small. There are a lot of debates around this topic and surely at the end, we will have a new protocol that can have a body without editing the server state, I am waiting for it.

AnWeber commented 1 year ago

@Gxmadix I fully agree with your arguments. I am just a lame duck. I fear that a firewall, Ingress or reverse proxy will remove my body. I have never tried it though. But maybe this would be a topic to bring up in my environment. I know the problem only too well.