Solidity HTTP client library for Foundry scripting
forge install Recon-Fuzz/solidity-http
import {HTTP} from "solidity-http/HTTP.sol";
Use builder functions to compose your request with headers, body, and query parameters.
contract MyScript is Script {
using HTTP for *;
HTTP.Client http;
function run() external {
HTTP.Response memory response = http.initialize().POST("https://httpbin.org/post")
.withHeader("Content-Type", "application/json")
.withHeader("Accept", "application/json")
.withBody('{"foo": "bar"}')
.request();
console.log("Status:", response.status);
console.log("Data:", response.data);
}
}
This library relies on Foundry's FFI cheatcode to call external processes. Enable it by:
- Passing the
--ffi
flag to your command:
forge test --ffi
- Or setting
ffi = true
in yourfoundry.toml
:
[profile.default]
ffi = true
- Foundry with FFI enabled:
- Either pass
--ffi
to commands (e.g.forge test --ffi
) - Or set
ffi = true
infoundry.toml
- Either pass
[profile.default]
ffi = true
- A UNIX-based machine with the following installed:
bash
,curl
,tail
,sed
,tr
,cast