https://github.com/hcarty/ezrest
Easy REST requests using cohttp
https://github.com/hcarty/ezrest
Last synced: 9 months ago
JSON representation
Easy REST requests using cohttp
- Host: GitHub
- URL: https://github.com/hcarty/ezrest
- Owner: hcarty
- License: apache-2.0
- Created: 2020-01-17T23:45:49.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2021-05-19T04:57:20.000Z (over 4 years ago)
- Last Synced: 2025-03-23T19:39:13.844Z (10 months ago)
- Language: OCaml
- Size: 15.6 KB
- Stars: 16
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - ezrest
README
# Easy REST requests using cohttp
See `ezrest.mli` for detailed usage information.
## Example usage
Let's take a look at what it's like to use Ezrest from a REPL.
```ocaml require-package=ezrest env=demo
# #require "ezrest"
```
First, a simple `HEAD` request.
```ocaml env=demo
# let site = Uri.of_string "http://jsonplaceholder.typicode.com/"
val site : Uri.t =
# Ezrest.head site
- : Cohttp.Response.t Ezrest.result =
Ok
{Cohttp.Response.encoding = Cohttp__.Transfer.Unknown; headers = ;
version = `HTTP_1_1; status = `OK; flush = false}
```
Now we can `GET` some content, failing if the site tries to redirect us.
```ocaml env=demo
# Ezrest.get ~follow:0 site
- : string Ezrest.result =
Ok
"\n\n\n\n\n\n\n
# Ezrest.put put_site
- : string Ezrest.result = Ok "{\n \"id\": 1\n}"
# let post_site = Uri.with_path site "/posts"
val post_site : Uri.t =
# Ezrest.post post_site
- : string Ezrest.result = Ok "{\n \"id\": 101\n}"
```
And `DELETE` if that's what's necessary.
```ocaml env=demo
# Ezrest.delete put_site
- : string Ezrest.result = Ok "{}"
```