On this page
Table of contents
Getting Started
Installation
Usage
FAQ
Testing
What's new
Migration Guide
Basic Syntax
Data Types
Expressions
Variables
Conditions
Commands
Arrays
Loops
Functions
Importing
Advanced Syntax
As Cast
Builtins
Type Condition
Compiler Flags
Standard Library
Array
Date
Environment
FileSystem
HTTP
Math
Test
Text
Contributing
How to
Guide
Compiler structure
Amber by Example
Backup Rotator
ShellCheck tester
Ubuntu Updater
Bot Detector
LSP Installer
Press
HTTP
fetch
pub fun fetch(url: Text, method: Text = "GET", data: Text = "", headers: [Text] = [""]): Text?
Makes a HTTP request using available command-line tools or bash's network sockets as failover.
For POST requests with a custom data type, you should include content-type header in headers[].
Usage
import { fetch } from "std/http"
let response = trust fetch("https://example.com")
// POST request example
let post_request = trust fetch("https://example.com", "POST", "hello world!", [
"content-type: text/plain"
])
file_download
pub fun file_download(url: Text, path: Text): Null?
Downloads a file from a given URL and saves it to a specified path using available command-line tools.
It checks for the availability of common command-line tools (curl, wget, and aria2c, in order) and uses the first available tool to perform the download.
If none of the tools are available, the function fails.
Usage
import { file_download } from "std/http"
file_download("https://example.com/file.zip", "/tmp/file.zip")
On this page
Table of contents
Getting Started
Installation
Usage
FAQ
Testing
What's new
Migration Guide
Basic Syntax
Data Types
Expressions
Variables
Conditions
Commands
Arrays
Loops
Functions
Importing
Advanced Syntax
As Cast
Builtins
Type Condition
Compiler Flags
Standard Library
Array
Date
Environment
FileSystem
HTTP
Math
Test
Text
Contributing
How to
Guide
Compiler structure
Amber by Example
Backup Rotator
ShellCheck tester
Ubuntu Updater
Bot Detector
LSP Installer
Press