I am excited to share my new AutoHotkey library that aims to extend the default 'download()' function without invoking WinHTTP comobj. This provides the ability to make HTTP GET requests with headers, parameters, and parsing. This library is based on Python's Requests library and is designed to simplify HTTP requests and responses in AutoHotkey.
Here are some of the key features of the library:
Simple syntax: With this library, you can make GET requests with just a single function call.
Custom headers and parameters: You can easily add custom headers and parameters to your requests.
JSON and text support: The library can automatically parse JSON responses and return them as objects or return plain text.
Error handling: The library raises exceptions for common HTTP errors, such as 404 Not Found or 500 Internal Server Error, so you can handle them gracefully in your code.
Todo:
-update params to optional
-add comprehension to python
-improve compilation
find release and details here: https://github.com/samfisherirl/ahk_requests.py
Note, these examples are subject to change. Use the github to receive updates and changes.
Code: Select all
#Include %A_ScriptDir%\lib\JXON.ahk
#Include %A_ScriptDir%\lib\ahk_requests.ahk
;grab python executable here https://github.com/samfisherirl/ahk_requests.py
;praise and credit to: https://github.com/TheArkive/JXON_ahk2
; Simple
url := "https://httpbin.org/get"
; see bottom for additional params
req := requests(url)
req.get()
msgbox(req.jdata["origin"])
msgbox(req.txt)
/*
**************************************************************
*/
; Intermediate example
url := "https://httpbin.org/get"
headers := Map("key1", "value1")
params := Map("key1", "value1")
req := requests(url, headers, params)
req.get()
msgbox(req.jdata["origin"])
msgbox(req.txt)
/*
**************************************************************
*/
; Complex example Airtable API
; https://github.com/josephbestjames/airtable.py
api_key := "xxxxx"
base_id := "yyyyy"
table_name := "zzzzzz"
url := "https://api.airtable.com/v0/" . base_id . "/" . table_name
headers := Map(
"Authorization",
"Bearer " . api_key
)
; headers := False => gets converted to {"User-Agent":"Mozilla/5.0 (Macintosh;...
params := Map("view", "Grid view")
req := requests(url, headers, params)
req.allowRedirect := True ;optional
req.stream := False ;optional
req.get()
msg := ""
for k, v in req.jdata
{
;json data
try {
msg .= k . ": " . v . "`n"
}
catch {
continue
}
}
msgbox(msg)
msgbox(req.txt)