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

Improvements for httpRequest #639

Merged
merged 3 commits into from
Aug 15, 2024
Merged

Improvements for httpRequest #639

merged 3 commits into from
Aug 15, 2024

Conversation

Asayukiii
Copy link
Contributor

@Asayukiii Asayukiii commented Aug 13, 2024

Type

  • Bug Fix
  • Functions: $httpRequest
  • Callbacks: <Callback Name>
  • Handlers: <Handler Type>
  • Others: ______

Dependencies (Third Party Modules) needed: None

Want a credit? Discord tag or other social media link: @Asayukiii

Referenced Issue: #NaN

Description

Recently, I saw an user trying to find a way to check if a given URL belongs to a GIF image.
I started to think about that, there isn't a way to know the content type of the response.
This is why I made the changes in this PR, also, I made the JSON parsing a bit safer than before.
I've tested the function using these references and worked as expected:

Test 1

Returning the whole API response

$httpRequest[https://jsonplaceholder.typicode.com/todos/1;GET]
# Returns: { "userId": 1, "id": 1, "title": "delectus aut autem", "completed": false }

Test 2

Returning a property from the API response (only if content-type is JSON)

$httpRequest[https://jsonplaceholder.typicode.com/todos/1;GET;;userId]
# Returns: 1

Test 3

Retrieving the content type of the API response

$httpRequest[https://jsonplaceholder.typicode.com/todos/1;GET;;contentType]
# Returns: application/json

Test 4

Fetching an image from Discord

$httpRequest[https://cdn.discordapp.com/attachments/1186843739369513043/1263476068430385272/MenYou-1.gif?ex=66bb54c8&is=66ba0348&hm=2f54b2e187fe2ccb52f94507670cf1bd095dbcc2d9b7d915a3233e6a3ebbc387&;get;;contentType]
# Returns: image/gif

Test 5

Fetching an HTML

$httpRequest[https://www.quora.com/Why-do-furries-exist;get;;contentType]
# Returns: text/html

$httpRequest[https://www.quora.com/Why-do-furries-exist;get]
# Returns: <!DOCTYPE html><html lang='en' dir='ltr' style='padding: 0;...

@Asayukiii Asayukiii marked this pull request as draft August 13, 2024 00:49
@Asayukiii Asayukiii marked this pull request as ready for review August 13, 2024 00:55
Copy link
Member

@Faf4a Faf4a left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Faf4a Faf4a requested review from Leref and supremesupreme August 13, 2024 02:20
@Faf4a Faf4a added type: improvement additional improvements state: pending Approval must be done first, to be accepted. type: function functions related aoi.js this issue/Pr is related to aoi.js labels Aug 13, 2024
@Faf4a
Copy link
Member

Faf4a commented Aug 15, 2024

Thank you!

@Faf4a Faf4a merged commit a6e9244 into aoijs:v6 Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aoi.js this issue/Pr is related to aoi.js state: pending Approval must be done first, to be accepted. type: function functions related type: improvement additional improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants