-
-
Notifications
You must be signed in to change notification settings - Fork 134
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
HTTP Function Refactor #641
base: v6
Are you sure you want to change the base?
Conversation
Hello, first of all, thanks for the pull request! 😃 However, this would be a breaking change therefore it would be better to allow users to also use the old behaviour of httpRequest for the time being. (should be fairly simple to implement) Which then can be removed in a future version (v6.9 probably) to give users more time to update their codes. The code changes look fine on a first look, I don't see any specific issues, I'll review them properly once I get home. |
Hey, I've got some feature suggestions: Since this is a breaking changes and you're saving HTTP request in the Also, I think renaming |
Sounds kinda good, but you can save all HTTP results in variables and objects.
|
Hey, these are some good commits you got in store for aoi.js! However I do want to point out some of my opinions that could be changed in your pull request.
|
Okay... I followed some suggestion. Mostly of them given by Kino. Changes- $httpAddHeader
+ $httpSetHeader
- $httpWasRedirected
+ $httpRedirected
- $httpRequest[url;method?;body?]
+ $httpRequest[url;method?;body?;encoding?]
- $httpGetContentType
I am still wondering if add "named requests" because you can easily save HTTP request data in objects. |
I think you can go for name request @Faf4a what do you think? |
Agreeing with ya |
@Asayukiii hi, You can move forward with the named request |
Done, I made the following changes. + $httpSetBody[body;name?]
+ $httpSetCredentials[credentialsText;name?]
- $httpClearOptions
+ $httpClearOptions[name?]
- $httpGetHeader[headerName]
+ $httpGetHeader[headerName;name?]
- $httpOk
+ $httpOk[name?]
- $httpRedirected
+ $httpRedirected[name?]
- $httpStatus
+ $httpStatus[name?]
- $httpRemoveHeader[headerName]
+ $httpRemoveHeader[headerName;name?]
- $httpSetHeader[headerName;headerValue]
+$httpSetHeader[headerName;headerValue;name?]
- $httpRequest[url;method?:body?;encoding?]
+ $httpRequest[url;method?:body?;encoding?;name?]
- $httpResult[..properties?]
+ $httpResult[name?:...properties?] Tested with the following code. client.readyCommand({
code: `
$log[REQUEST_3_SUMMARY: {
redirected: $httpRedirected[buffer],
success: $httpOk[buffer],
status: $httpStatus[buffer],
result: buffer stuff,
contentType: $httpGetHeader[content-type;buffer]
}]
$httpRequest[https://dummyjson.com/image/150;GET;;utf-8;buffer]
$log[REQUEST_2_SUMMARY: {
redirected: $httpRedirected[login],
success: $httpOk[login],
status: $httpStatus[login],
result: $httpResult[login],
contentType: $httpGetHeader[content-type;login]
}]
$httpRequest[https://dummyjson.com/auth/login;POST;;;login]
$httpSetHeader[Content-Type;application/json;login]
$httpSetCredentials[include;login]
$httpSetBody[{
"username": "emilys",
"password": "youshallnotpass"
};login]
$log[REQUEST_1_SUMMARY: {
redirected: $httpRedirected,
success: $httpOk,
status: $httpStatus,
result: $httpResult,
contentType: $httpGetHeader[content-type]
}]
$httpRequest[https://jsonplaceholder.typicode.com/todos/1;GET]
`
}) |
Will check later. cc @supremesupreme you too please thanks |
LGTM, not approving as it'd be better to not include it in 6.9 but rather a later version and announcing the breaking change first. |
Resolve conflicts, additionally it looks good. This a major breaking change, definitely next update. |
Following my suggestion, here are my changes.
Refactors
$httpRequest
The headers, error and property fields were deleted. Current usage is:
This function will create a property called "http" in
d.data
where all request info will be saved.Additions
$httpAddHeader
Adds a header to be used in the request.
Usage:
Example
$httpClearOptions
Clears the data that a past request must have cached.
Usage:
Example
$httpGetContentType
Retrieves the response content type.
Usage:
Example
$httpGetHeader
Retrieves a response header.
Usage:
Example
$httpOk
Retrieves whether request has a success code (boolean).
Usage
Example
$httpRemoveHeader
Removes a header from the HTTP data.
Usage:
Example
$httpResult
Retrieves a result from the HTTP request.
Usage:
Example
$httpStatus
Returns the status of the HTTP response.
Usage:
Example
$httpWasRedirected
Returns whether HTTP request was redirected to another endpoint/site.
Usage:
Example
Tests
Any comments, ideas about this are welcome!
This comment was edited by a maintainer to make it easier to scroll to the comments.