Http client request from object
This commit is contained in:
1 parent
c35779b211
commit
e941bc2439
2 files changed
+21
No files matched your search
@@ -40,6 +40,20 @@ namespace HttpClient
|
|||||||
return (new HttpRequest()).Method("HEAD").Url(url)
|
return (new HttpRequest()).Method("HEAD").Url(url)
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
function FromObject(obj as object) as HttpRequest
|
||||||
|
request = new HttpRequest()
|
||||||
|
|
||||||
|
for each key in obj
|
||||||
|
if IsFunction(request[key])
|
||||||
|
request[key](obj[key])
|
||||||
|
else
|
||||||
|
throw `Invalid key: "${key}" in object passed to HttpClient.FromObject`
|
||||||
|
end if
|
||||||
|
end for
|
||||||
|
|
||||||
|
return request
|
||||||
|
end function
|
||||||
|
|
||||||
class HttpRequest
|
class HttpRequest
|
||||||
|
|
||||||
public urlTransfer as object
|
public urlTransfer as object
|
||||||
@@ -235,6 +249,9 @@ namespace HttpClient
|
|||||||
else if m._method = "HEAD"
|
else if m._method = "HEAD"
|
||||||
m._sent = m.urlTransfer.AsyncHead()
|
m._sent = m.urlTransfer.AsyncHead()
|
||||||
else
|
else
|
||||||
|
if StringUtils.IsNullOrEmpty(m._method)
|
||||||
|
throw "Http request method not set"
|
||||||
|
end if
|
||||||
m.urlTransfer.SetRequest(m._method)
|
m.urlTransfer.SetRequest(m._method)
|
||||||
body = m._body
|
body = m._body
|
||||||
if body = invalid
|
if body = invalid
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ function IsDouble(obj as dynamic) as boolean
|
|||||||
return obj <> invalid and GetInterface(obj, "ifDouble") <> invalid
|
return obj <> invalid and GetInterface(obj, "ifDouble") <> invalid
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
function IsFunction(obj as dynamic) as boolean
|
||||||
|
return obj <> invalid and GetInterface(obj, "ifFunction") <> invalid
|
||||||
|
end function
|
||||||
|
|
||||||
function ValidString(obj as object) as string
|
function ValidString(obj as object) as string
|
||||||
if obj <> invalid and GetInterface(obj, "ifString") <> invalid
|
if obj <> invalid and GetInterface(obj, "ifString") <> invalid
|
||||||
return obj
|
return obj
|
||||||
|
|||||||
Reference in new issue
Block a user