zed_extension_api: Add fetch (#13716)

This PR adds a new `fetch` function to the `zed_extension_api` to allow
fetching a URL through the Wasm host.

Currently we only support GET requests and return the response body as a
string.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-07-01 16:58:00 -04:00 committed by GitHub
parent e7214a429d
commit 3419f5fc42
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 56 additions and 1 deletions

View file

@ -19,6 +19,7 @@ pub use wit::{
github_release_by_tag_name, latest_github_release, GithubRelease, GithubReleaseAsset,
GithubReleaseOptions,
},
zed::extension::http_client::{fetch, HttpRequest, HttpResponse},
zed::extension::nodejs::{
node_binary_path, npm_install_package, npm_package_installed_version,
npm_package_latest_version,

View file

@ -2,6 +2,7 @@ package zed:extension;
world extension {
import github;
import http-client;
import platform;
import nodejs;

View file

@ -0,0 +1,16 @@
interface http-client {
/// An HTTP request.
record http-request {
/// The URL to which the request should be made.
url: string,
}
/// An HTTP response.
record http-response {
/// The response body.
body: string,
}
/// Performs an HTTP request and returns the response.
fetch: func(req: http-request) -> result<http-response, string>;
}