Comments (8)
What handles schema errors?
- har-validator is used to validate the HAR input based on HAR 1.2 Spec
- in
src/index.js
I specifically add any missing input properties before validation, to make it simpler and faster to create input json files (rather than having to add in an emptycookies: []
array, and specificyhttpVersion
every time for example)
It seems weird having to make checks such as:
if (this.source.postData && (this.source.postData.params || this.source.postData.text)) {
yes, it is, and you shouldn't be doing that, at least, it seems you're approaching the issue thinking only of Unirest. there are libraries that allow you to set a raw body AND set parameterized POST data at the same time ... I see no reason for httpsnippet to limit that behavior ... it should be left to the discretion of the implementer to use what makes sense for the library.
keeping the implementation simple, it would be enough to check that .text
and .params
are mutually exclusive:
if (this.source.postData.text) {
// request body
}
if (!this.source.postData.text && this.source.postData.params) {
// construct post params
}
Cannot build a native JSON object when mimeType is 'application/json'
other than JavaScript, I'm not aware of any language that has native JSON support, so therefore if you want to implement whatever native equivalent of JSON, you probably have to parse it first with JSON.prase
, then process / convert it to that native as well ... I don't see any way around that?
No way to know the response type in advance?
I'm going to be soon adding the ability to reference a FULL HAR object / file rather than just the request portion of it, which should give the ability to review the response object and construct accordingly.
from httpsnippet.
yes, it is, and you shouldn't be doing that
No, I have no other choice. It makes me do even uglier things for Unirest. I need a way to know wheter or not a request as a body. And it seems that the existence of postData
actually doesn't mean anything.
I'm not aware of any language that has native JSON support
I should have put native in quotes but you got the idea.
so therefore if you want to implement whatever native equivalent of JSON,
I know I could parse it, I'm just saying now I have to do it for every language because your schema doesn't already do it...
Basically I know your points. I am just trying to start a discussion about whether or not HAR is the right schema to handle snippets creation honestly... I find the Mashape one way more appropriate.
from httpsnippet.
har-validator is used to validate the HAR input based on HAR 1.2 Spec
I know that. Same thing, I'm just saying we should add a layer of error handling. When the HAR format is valid but the informations are not enough to properly build a request snippet. (see the postData example, and #8)
from httpsnippet.
And it seems that the existence of postData actually doesn't mean anything.
yes, as mentioned, postData
is always generated regardless of source, I still think you're not looking closer at the HAR spec, here's another valid way of doing body work:
if (this.source.postData.text) {
// request body
} else {
if (this.source.postData.params) {
// construct post params
}
}
basically the existence of postData.text
overrides everything (and is the easiest, just sent content-type
header and send the string of text)
also, postData.params
are not JUST the key/value pair for application/x-www-form-urlencoded
... in the case of multipart/form-data
you have to traverse each param, and parse it's value individually as some would be a file, others can be any content (text, video, etc ...)
ex:
"params": [
{
"name": "file",
"value": "[content of the pdf file]",
"fileName": "example.pdf",
"contentType": "application/pdf",
}
]
in this case you should parse the fileName
field and use that in the code (to look up and read content of the file) then pass that content as the multipart/form-data
request with the specified name.
I know I could parse it, I'm just saying now I have to do it for every language because your schema doesn't already do it...
I could pre-parse the JSON object into a property called this.source.json
or something ... but then I would also have to traverse all the potential multipart/form-data
params and look for any existence of application/json
(or any of the 5 other headers representing JSON) and parse those as well ... its doable... but seems like a lot ... any better suggestions?
I find the Mashape one way more appropriate.
the Mashape schema is lacking in many places, it only covers the most popular use-cases and certainly does not deal with multipart/form-data
at all!
from httpsnippet.
this is a good discussion regardless, perhaps if any valuable lessons come out of this, we can share with the HAR community :)
from httpsnippet.
(Your code snippet for body work still does not do the job if one wants a definitive way of knowing whether or not a request has a body. Doing it like that, I would have to duplicate my code. The if statement mentioned in the first comment is still the only way of knowing whether or not the request has a body.)
True for the multipart requests, however I still believe the Mashape snippets are simpler (and they are actually way shorter (thanks also to the helpers)) but also because the schema is simply less flexible.
from httpsnippet.
with recent guideline added and utility properties, this solves 90% if not all the of concerns discussed here...
from httpsnippet.
I approve this message.
from httpsnippet.
Related Issues (20)
- C# RestSharp is using deprecated syntax HOT 2
- Wiki is empty HOT 1
- future plan to add typescript?
- why is the difference between the code generated in postman and by httpsnippet? HOT 1
- Can you make a new release on npm please? HOT 1
- Typescript error when `postData` is missing HOT 2
- Update README.md and Wiki HOT 1
- does not work with vite HOT 1
- Generate Robot Framework
- Maintainer activity HOT 7
- Content-Length invalid for unicode text HOT 1
- Support line wrap or fixed width in generated code snippet string
- Error: strict mode: unknown keyword: "afterRequest" HOT 2
- New Version HOT 4
- Error: TypeError - Cannot read properties of undefined (reading 'toString') HOT 1
- Support for Crystal Language Code Generation
- I try to generate HTTP Snippet Code for Download File from Server, but I'm not able to download file because my HTTP Request Snippet is incomplete
- BUG: Http default clientId error
- Httpsnippet uses ajv but doesn't actually depend on it
- the URL is not decoded
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from httpsnippet.