Giter VIP home page Giter VIP logo

curly's Introduction

Curly - The Dumbest Http Client

Curly is a brain dead wrapper around the curl command line utility designed to provide a 0 dependency solution for applications that want to create some very simple HTTP requests. It is not blazing fast, or async, but at least it involves no C bindings, it's trivial to vendor, and the API can be learned in 5 minutes.

Here's a simple example:

match Curly.(run (Request.make ~url:"https://opam.ocaml.org" ~meth:`GET ())) with
| Ok x ->
  Format.printf "status: %d\n" x.Curly.Response.code;
  Format.printf "headers: %a\n" Curly.Header.pp x.Curly.Response.headers;
  Format.printf "body: %s\n" x.Curly.Response.body
| Error e ->
  Format.printf "Failed: %a" Curly.Error.pp e

There's not much more to it than this. Consult curly.mli to see how to construct various requests and read responses, or read the online documentation.

curly's People

Contributors

bikallem avatar c-cube avatar emillon avatar jonahbeckford avatar leonidas-from-xiv avatar rawleyfowler avatar rgrinberg avatar shonfeder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

curly's Issues

Cutting a new release?

I've got #8 and #6 in a Windows (DKML) opam repository, but it would be great if those were also in the main opam repository.

Can a new release be made?

curl command not found error even when curl is in path

Consider the following scenario where curl is in path in a NixOS installation:

$ which curl
/nix/store/m2h1p50yvcq5j9b3hkrwqnmrr9pbkzpz-curl-7.86.0-bin/bin/curl

`Curly.get "google.com" fails as below:

─( 16:39:13 )─< command 0 >─────────────────────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # #require "curly";;
─( 16:39:13 )─< command 1 >─────────────────────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # Curly.get "google.com";;
- : (Curly.Response.t, Curly.Error.t) result =
Result.Error
 (Curly.Error.Bad_exit
   {Curly.Process_result.status = Unix.WEXITED 127;
    stderr = "/bin/sh: line 1: curl: command not found\n"; stdout = ""})

When curl is told to follow redirects, response body includes headers

If you use ~args:["-L"] to make curl follow redirects, response body mistakenly includes headers of the final reply.

# let http_get url =
  match Curly.(run ~args:["-L"] (Request.make ~url:url ~meth:`GET ())) with
  | Ok x -> x.Curly.Response.body
  | Error e -> Format.printf "%a" Curly.Error.pp e; failwith "Failed to fetch the feed"
;;
val http_get : string -> string = <fun>

(* HTTP → HTTPS 301 redirect *)
# http_get "http://baturin.org/blog/atom-ocaml.xml" ;;
- : string =
"HTTP/2 200 \r\ndate: Sat, 29 Aug 2020 21:46:41 GMT\r\nserver: Apache/2.4.43 (Fedora) OpenSSL/1.1.1g\r\nlast-modified: Fri, 28 Aug 2020 19:23:29 GMT\r\netag: \"22aa-5adf4fcd7ab93\"\r\naccept-ranges: bytes\r\ncontent-length: 8874\r\ncontent-type: text/xml\r\n\r\n<?xml version='1.0' encoding='UTF-8'?>\n<feed xmlns=\"http:/"... (* string length 9115; truncated *)

(* No redirect *)
# http_get "https://baturin.org/blog/atom-ocaml.xml" ;;
- : string =
"<?xml version='1.0' encoding='UTF-8'?>\n<feed xmlns=\"http://www.w3.org/2005/Atom\" xml:lang=\"en\">\n  <id>https://baturin.org/blog/atom.xml</id>\n  <title>Daniil Baturin's blog</title>\n  <updated>2020-08-28T19:23:29.169634+00:00</updated>\n  <author>\n    <name>Daniil Baturin</name>\n    <email>daniil+webs"... (* string length 8874; truncated *)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.