Skip to content

Commit

Permalink
Update documentation for latest Gleam
Browse files Browse the repository at this point in the history
  • Loading branch information
lpil committed Jan 12, 2024
1 parent 2a9a22e commit c93c9c2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
23 changes: 9 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,23 @@ Bindings to JavaScript's built in HTTP client, `fetch`.

```gleam
import gleam/fetch
import gleam/http.{Get}
import gleam/http/request
import gleam/http/response.{Response}
import gleam/javascript/promise.{try_await}
import gleam/http/response
import gleam/javascript/promise
pub fn main() {
// Prepare a HTTP request record
let req = request.new()
|> request.set_method(Get)
|> request.set_host("test-api.service.hmrc.gov.uk")
|> request.set_path("/hello/world")
|> request.prepend_header("accept", "application/vnd.hmrc.1.0+json")
let assert Ok(req) = request.to("https://example.com")
// Send the HTTP request to the server
use resp <- try_await(fetch.send(req))
use resp <- try_await(fetch.read_text_body(resp))
use resp <- promise.try_await(fetch.send(req))
use resp <- promise.try_await(fetch.read_text_body(resp))
// We get a response record back
assert Response(status: 200, ..) = resp
resp.status
// -> 200
assert Ok("application/json") = response.get_header(resp, "content-type")
assert "{\"message\":\"Hello World\"}" = resp.body
response.get_header(resp, "content-type")
// -> Ok("text/html; charset=UTF-8")
promise.resolve(Ok(Nil))
}
Expand Down
6 changes: 3 additions & 3 deletions gleam.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ links = [

[dependencies]
gleam_http = "~> 3.1"
gleam_javascript = "~> 0.3"
gleam_stdlib = "~> 0.32"
gleam_javascript = "~> 0.3 or ~> 1.0
gleam_stdlib = "~> 0.32 or ~> 1.0"

[dev-dependencies]
gleeunit = "~> 0.8"
gleeunit = "~> 1.0"

6 changes: 3 additions & 3 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# You typically do not need to edit this file

packages = [
{ name = "gleam_http", version = "3.5.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "0B09AAE8EB547C4F2F2D3F8917A0A4D2EF75DFF0232389332BAFE19DBBFDB92B" },
{ name = "gleam_javascript", version = "0.6.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_javascript", source = "hex", outer_checksum = "BFEBB63ABE4A1694E07DEFD19B160C2980304B5D775A89D4B02E7DE7C9D8008B" },
{ name = "gleam_stdlib", version = "0.32.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "07D64C26D014CF570F8ACADCE602761EA2E74C842D26F2FD49B0D61973D9966F" },
{ name = "gleam_http", version = "3.5.3", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "C2FC3322203B16F897C1818D9810F5DEFCE347F0751F3B44421E1261277A7373" },
{ name = "gleam_javascript", version = "0.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_javascript", source = "hex", outer_checksum = "B5E05F479C52217C02BA2E8FC650A716BFB62D4F8D20A90909C908598E12FBE0" },
{ name = "gleam_stdlib", version = "0.34.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "1FB8454D2991E9B4C0C804544D8A9AD0F6184725E20D63C3155F0AEB4230B016" },
{ name = "gleeunit", version = "0.11.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "1397E5C4AC4108769EE979939AC39BF7870659C5AFB714630DEEEE16B8272AD5" },
]

Expand Down

0 comments on commit c93c9c2

Please sign in to comment.