Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
# ezhttp

HTTP client and server for [Bend 2](https://github.com/bendlang/bend).
It needs bend 2.0.32 or later (the server binds `TCP.listen(host, port)`).

## Install

With [Bend](https://github.com/bendlang/bend) alone there is nothing to
install: import ezhttp by its hub name and `bend` fetches it from
It needs bend 2.0.32 or later (the server binds `TCP.listen(host, port)`).
ezhttp is built and checked on bend 2.0.34.

With [Bend](https://github.com/bendlang/bend) alone there is no install
step: import ezhttp by its hub name and `bend` fetches it from
[the hub](https://hub.bend-lang.com) into `~/.bend/lib` on the first run.
`0x5e4e2a9db839a0214ace6923b04b685b` is ezhttp v0.6.0.
`emerging-ezhttp@0.8.0.0` is ezhttp v0.8.0:

```
import 0x5e4e2a9db839a0214ace6923b04b685b/main.bend as Http
import emerging-ezhttp@0.8.0.0/main.bend as Http
```

That name resolves to `0xf1c957a470368870a6d1d62a8c0cbe32`.
To pin by content instead, import `0xf1c957a470368870a6d1d62a8c0cbe32/main.bend`.

Or with [ez](https://github.com/Emerging-Patterns/ez), which records the
package in `ez.toml` (`ez init` makes one):

Expand Down Expand Up @@ -42,8 +47,8 @@ wire/runtime layer (`EZ_LIBSSL` when needed). `https` selects that TLS path
and port 443.

```
import 0x5e4e2a9db839a0214ace6923b04b685b/main.bend as Http
import 0x5e4e2a9db839a0214ace6923b04b685b/src/client.bend as Client
import emerging-ezhttp@0.8.0.0/main.bend as Http
import emerging-ezhttp@0.8.0.0/src/client.bend as Client

def main() -> IO(Client.Response):
Http.http.get("https://example.com/")
Expand All @@ -64,8 +69,8 @@ per connection, calls a pure handler, and writes one response
in v0 for the server. A HEAD response is written with an empty body.

```
import 0x5e4e2a9db839a0214ace6923b04b685b/main.bend as Http
import 0x5e4e2a9db839a0214ace6923b04b685b/src/http.bend as Msg
import emerging-ezhttp@0.8.0.0/main.bend as Http
import emerging-ezhttp@0.8.0.0/src/http.bend as Msg

def handle(req: Msg.Request) -> Msg.Reply:
match req:
Expand All @@ -81,10 +86,10 @@ def main() -> IO(Unit):
Cookies, `Cache-Control`, and CORS are pure helpers on the same messages.

```
import 0x5e4e2a9db839a0214ace6923b04b685b/main.bend as Http
import 0x5e4e2a9db839a0214ace6923b04b685b/src/http.bend as Msg
import 0x5e4e2a9db839a0214ace6923b04b685b/src/cookie.bend as Cookie
import 0x5e4e2a9db839a0214ace6923b04b685b/src/cors.bend as Cors
import emerging-ezhttp@0.8.0.0/main.bend as Http
import emerging-ezhttp@0.8.0.0/src/http.bend as Msg
import emerging-ezhttp@0.8.0.0/src/cookie.bend as Cookie
import emerging-ezhttp@0.8.0.0/src/cors.bend as Cors

def authed() -> Msg.Header:
Http.basic("user", "pass")
Expand All @@ -100,8 +105,8 @@ def cross(cfg: Cors.Cfg, req: Msg.Request, reply: Msg.Reply) -> Msg.Reply:
```

```
import 0x81c67699424929b5c44cd8577e18117f/main.bend as Ezjson
import 0x81c67699424929b5c44cd8577e18117f/src/value.bend as Value
import emerging-ezjson@1.1.0.0/main.bend as Ezjson
import emerging-ezjson@1.1.0.0/src/value.bend as Value

def read.of(got: Maybe<&2, Value.Json>) -> Maybe<&2, String>:
match got:
Expand Down
6 changes: 3 additions & 3 deletions ez.lock.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ LICENSE = "309f5aae946e4db157750e002fb179a74ed0fe27fce09a7be68a6977b14f205f"
[tools]
[tools.bolt]
git = "https://github.com/Emerging-Patterns/bolt"
rev = "d5a67600a96ba423f2212bd661a30c1fba38eb55"
tag = "v1.9.0"
rev = "91efe4bbaad91953652794ad55be7b49c10a2eff"
tag = "v1.11.0"
root = "."
narHash = "sha256-HmJ8J1xDshBdSWXIiEp48GZ9qHsm+bmpHw06ZWwcDVE="
narHash = "sha256-0xjoxoByI8PKBrbFy4eYGbKQ3ZVscknZLKkWQroYAUI="
entry = "main.bend"
10 changes: 5 additions & 5 deletions ez.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "ezhttp"
entry = "main.bend"

[deps]
[deps.ezjson]
hash = "0x81c67699424929b5c44cd8577e18117f"
git = "https://github.com/Emerging-Patterns/ezjson"
Expand All @@ -10,11 +10,11 @@ tag = "v1.1.0"
root = "."
narHash = "sha256-yHxl1aW4luf2bdPqOUcULhOEZLlcaTOWjTrPJys4CMI="
entry = "main.bend"

[tools]
[tools.bolt]
git = "https://github.com/Emerging-Patterns/bolt"
rev = "d5a67600a96ba423f2212bd661a30c1fba38eb55"
tag = "v1.9.0"
rev = "91efe4bbaad91953652794ad55be7b49c10a2eff"
tag = "v1.11.0"
root = "."
narHash = "sha256-HmJ8J1xDshBdSWXIiEp48GZ9qHsm+bmpHw06ZWwcDVE="
narHash = "sha256-0xjoxoByI8PKBrbFy4eYGbKQ3ZVscknZLKkWQroYAUI="
entry = "main.bend"
47 changes: 7 additions & 40 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 9 additions & 16 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
url = "github:bendlang/bend/777ee0b55c485afdd7e68bd917b3d23a88d77371";
inputs.nixpkgs.follows = "nixpkgs";
};
# ez 1.3.0 runs on bend 2.0.34, so its bend follows this flake's bend:
# ez, `ez prove` and bolt all build on 2.0.34.
inputs.ez = {
url = "github:Emerging-Patterns/ez";
inputs.nixpkgs.follows = "nixpkgs";
# ez and its bolt stay on the bend ez's own flake.lock records until ez
# releases on 2.0.34, so ez's inputs.bend is pinned, not followed. The
# package's own builds and its proofs (checks.proofs) run on 2.0.34.
inputs.bend.url = "github:bendlang/bend/af569d4826913b2ce3557e9829ccad31fcf86f94";
inputs.bend.follows = "bend";
};

outputs = { self, nixpkgs, ... }@inputs:
Expand All @@ -25,7 +24,7 @@
ez = inputs.ez.lib.${system};
ezBin = inputs.ez.packages.${system}.default;
bend = inputs.bend.packages.${system}.default;
bolt = ez.toolPackage { name = "bolt"; src = self; wrapFlags = [ "--gpu" "off" ]; };
bolt = ez.toolPackage { name = "bolt"; src = self; inherit bend; wrapFlags = [ "--gpu" "off" ]; };
bend-cc = ez.bend-cc;

bench = import ./bench {
Expand All @@ -42,22 +41,16 @@
apps.${system} = bench.apps;

checks.${system} = {
# every PROOF.bend on this flake's bend: its first line must be
# ALL PROOFS CHECK. ez.mkProofs comes back when ez runs on 2.0.34.
# ENTRY.bend states the laws on main.bend and client.bend,
# which reach the wire effect, so its verdict is SOME PROOFS FAIL;
# its only error may be the list of defs relying on foreign code.
proofs = pkgs.runCommand "ezhttp-proofs" {
proofs = ez.mkProofs { ez = ezBin; src = self; };
# ENTRY.bend states the laws on main.bend and client.bend, which
# reach the wire effect, so its verdict is SOME PROOFS FAIL; its only
# error may be the list of defs relying on foreign code.
entry = pkgs.runCommand "ezhttp-entry" {
nativeBuildInputs = [ bend ];
BEND_LIB = ez.bendLib ./ez.lock.toml;
} ''
export HOME=$TMPDIR
cp -r ${self} src && chmod -R u+w src && cd src
for p in $(find . -name PROOF.bend -not -path './.ez/*' | sort); do
first=$(cd "$(dirname "$p")" && bend "$(basename "$p")" | head -n 1)
echo "$p: $first"
[ "$first" = "ALL PROOFS CHECK" ] || exit 1
done
out_entry=$(bend ENTRY.bend 2>&1 || true)
echo "$out_entry" | head -n 2
[ "$(echo "$out_entry" | sed -n 1p)" = "SOME PROOFS FAIL" ] || exit 1
Expand Down
Loading