derekkraan / curl_req

req to curl and back
https://hex.pm/packages/curl_req
MIT License
38 stars 2 forks source link

CurlReq

Req is awesome, but the world speaks curl.

Next time you're debugging a 3rd party API and need to ask for support, you can just toss in this line:

|> CurlReq.inspect()

And you'll have the full curl command.

Read the announcement here.

Usage

Req to Curl

# Turn a Req request into a `curl` command.

iex> Req.new(url: "/fact", base_url: "https://catfact.ninja/")
...> |> CurlReq.to_curl()
"curl --compressed -X GET https://catfact.ninja/fact" 

# Or use `CurlReq.inspect/2` to inspect inline.

iex> Req.new(url: "/fact", base_url: "https://catfact.nijna/")
...> |> CurlReq.inspect(label: "MY REQ")
...> # |> Req.request!()

Curl to Req

CurlReq also implements the ~CURL sigil, which converts a curl command to its corresponding Req request.

iex> import CurlReq
...> ~CURL(curl https://www.google.com)
...> # |> Req.request!()

Req Plugin

One final feature to note the Req plugin, CurlReq.Plugin. Use CurlReq.Plugin.attach/2 to set up curl logging (inspired by TeslaCurl).

iex> Req.new(url: "/fact", base_url: "https://catfact.ninja/")
...> |> CurlReq.Plugin.attach()
...> # |> Req.request!()

Installation

The package can be installed by adding curl_req to your list of dependencies in mix.exs:

def deps do
  [
    {:curl_req, "~> 0.98.0"}
  ]
end

The docs can be found at https://hexdocs.pm/curl_req.

Contributions

Contributions are welcome! There are gaps in the library, and this is open source, so let's work together to fill them!

How to contribute