Skip to content

📡 Make requests to HTTP servers

License

Notifications You must be signed in to change notification settings

midas-framework/httpc

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

httpc

Bindings to Erlang's built in HTTP client, httpc.

import gleam/httpc
import gleam/http.{Get, Response}
import gleam/should

pub fn main() {
  // Prepare a HTTP request record
  let resp = http.default_req()
    |> http.set_method(Get)
    |> http.set_host("test-api.service.hmrc.gov.uk")
    |> http.set_path("/hello/world")
    |> http.prepend_req_header("accept", "application/vnd.hmrc.1.0+json")

  // Send the HTTP request to the server
  try resp = httpc.send(req)

  // We get a response record back
  resp.status
  |> should.equal(200)

  resp
  |> http.get_resp_header("content-type")
  |> should.equal(Ok("application/json"))

  resp.body
  |> should.equal("{\"message\":\"Hello World\"}")

  Ok(resp)
}

Installation

This package can be installed by adding gleam_httpc to your rebar.config dependencies:

{deps, [
    gleam_httpc
]}.

You may also need to add the gleam_httpc OTP application to your .app.src file, depending on how you run your program.

{applications, [
    kernel,
    stdlib,
    ssl,
    inets,
    gleam_stdlib,
    gleam_httpc
]},

About

📡 Make requests to HTTP servers

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 89.0%
  • Erlang 11.0%