https://github.com/gleam-lang/fetch
📡 Make requests to HTTP servers with fetch
https://github.com/gleam-lang/fetch
Last synced: about 1 hour ago
JSON representation
📡 Make requests to HTTP servers with fetch
- Host: GitHub
- URL: https://github.com/gleam-lang/fetch
- Owner: gleam-lang
- License: apache-2.0
- Created: 2021-09-02T18:40:36.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-19T23:34:41.000Z (about 1 year ago)
- Last Synced: 2024-04-22T11:31:06.621Z (about 1 year ago)
- Language: Gleam
- Size: 39.1 KB
- Stars: 31
- Watchers: 4
- Forks: 8
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
- awesome-gleam - gleam_fetch - [📚](https://hexdocs.pm/gleam_fetch/) - Make HTTP requests in Gleam JavaScript with Fetch (Packages / HTTP Clients)
README
# Gleam Fetch
Make HTTP requests in Gleam JavaScript with Fetch.
```sh
gleam add gleam_fetch@1 gleam_http
``````gleam
import gleam/fetch
import gleam/http/request
import gleam/http/response
import gleam/javascript/promisepub fn main() {
let assert Ok(req) = request.to("https://example.com")// Send the HTTP request to the server
use resp <- promise.try_await(fetch.send(req))
use resp <- promise.try_await(fetch.read_text_body(resp))// We get a response record back
resp.status
// -> 200response.get_header(resp, "content-type")
// -> Ok("text/html; charset=UTF-8")promise.resolve(Ok(Nil))
}
```Documentation can be found at [https://hexdocs.pm/gleam_fetch](https://hexdocs.pm/gleam_fetch).
> [!WARNING]
> If you are running your Gleam project on the Erlang target (the default for
> new Gleam projects) then you will want to use a different library which can
> run on Erlang, such as [`gleam_httpc`](https://github.com/gleam-lang/httpc).