List of Nasal extension functions: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
Line 430: Line 430:
     return file_path;
     return file_path;
}
}
</syntaxhighlight>
=== http (HTTP module, v. 2.99+) ===
Get remote data using the HTTP.
==== <tt>load()</tt> ====
Load resource identified by its URL into memory.
<syntaxhighlight lang="nasal">
var request = http.load(<url>);
</syntaxhighlight>
<syntaxhighlight lang="nasal">
http.load("http://example.com/test.txt")
    .done(func(r) print("Got response: " ~ r.response));
</syntaxhighlight>
==== <tt>save()</tt> ====
Save resource to a local file.
<syntaxhighlight lang="nasal">
var request = http.save(<url>, <file_path>);
</syntaxhighlight>
<syntaxhighlight lang="nasal">
http.save("http://example.com/test.png", getprop('/sim/fg-home') ~ '/cache/test.png')
    .fail(func print("Download failed!"))
    .done(func(r) print("Finished request with status: " ~ r.status ~ " " ~ r.reason))
    .always(func print("Request complete (fail or success)"));
</syntaxhighlight>
</syntaxhighlight>


166

edits

Navigation menu