Skip to content

Releases: zigzap/zap

Release v0.7.0

21 Apr 18:29
Compare
Choose a tag to compare
Release v0.7.0 Pre-release
Pre-release

ZAP Release v0.7.0

Updates

Update to Zig 0.12

With the help of our awesome contributers, we have a new release:

  • zap is now officially based on Zig 0.12.0!
  • tests have been updated to use the latest std.http client
  • @desttinghim added getHeaderCommon to zap.Request
  • @leroycep improved error return traces in zap.Request.sendError()
  • @dasimmet and @dweiller fixed the use of @fieldParentPtr to the new style
  • @xflow-systems improved the write function of websockets

Users of sendError(): the API has changed! The doc comment has been updated. The new way of using it is:

r.sendError(err, if (@errorReturnTrace()) |t| t.* else null, 505);

The new version outputs much nicer error traces.

Note: there will likely be a zig-master branch in the future that gets updated with breaking changes of Zig master. For sanity reasons, it will not be called zig-0.13.0 but zig-master. I'll update the README accordingly then.

Note 2: I merged PRs and fixed the tests while waiting for my plane to board, then finished on the plane. If I might have rushed it and oopsied something up, I'll apologize and follow up with a bugfix release.

One open issue is using openssl on macOS, especially with openssl in custom locations, like homebrew-installed versions. If anyone wants to look into that: PRs are welcome 😊!

Many thanks again to everyone who helped out!

Using it

To use in your own projects, put this dependency into your build.zig.zon:

        // zap v0.7.0
        .zap = .{
            .url = "https://github.com/zigzap/zap/archive/refs/tags/v0.7.0.tar.gz",
            .hash = "1220a1cb1822ea77083045d246db5d7a6f07a8ddafa69c98dee367560f9ce667fd8d",
        }

Here is a complete build.zig.zon example:

.{
    .name = "My example project",
    .version = "0.0.1",

    .dependencies = .{
        // zap v0.7.0
        .zap = .{
            .url = "https://github.com/zigzap/zap/archive/refs/tags/v0.7.0.tar.gz",
            .hash = "1220a1cb1822ea77083045d246db5d7a6f07a8ddafa69c98dee367560f9ce667fd8d",
        },
    },
    .paths = .{
        "",
    },
}

Then, in your build.zig's build function, add the following before exe.install():

    const zap = b.dependency("zap", .{
        .target = target,
        .optimize = optimize,
    });
    exe.addModule("zap", zap.module("zap"));
    exe.linkLibrary(zap.artifact("facil.io"));

Release v0.6.0

23 Mar 23:47
Compare
Choose a tag to compare
Release v0.6.0 Pre-release
Pre-release

ZAP Release v0.6.0

Updates

Breaking change in zap.Router

Latest zig master does not allow for multiple copies of the same anonymous type anymore. This broke zap.RequestHandler used by zap.Router.

So I rewrote zap.Router and zap.RequestHandler is gone.

To keep the APIs identical for both zig versions, I applied the rewrite patch also to the zig 0.11.0 (master) branch.

From a user perspective not much changed:

  • for unbound route handlers, use zap.Router.handle_route_unbound.
  • use zap.Router.on_request_handler() to get the request function to pass to a Listener.

Note: the 0.12.0 branch is currently broken with regard to tests due to changes in std.http.

Changelog in alphabetical order:

GitHub Action (1):
Update README

Rene Schallner (2):
trying to add mastercheck badge to README
re-write of zap.Router, fix #83

Using it

To use in your own projects, put this dependency into your build.zig.zon:

        // zap v0.6.0
        .zap = .{
            .url = "https://github.com/zigzap/zap/archive/refs/tags/v0.6.0.tar.gz",
            .hash = "1220a5a1e6b18fa384d8a98e5d5a25720ddadbcfed01da2e4ca55c7cfb3dc1caa62a",
        }

Here is a complete build.zig.zon example:

.{
    .name = "My example project",
    .version = "0.0.1",

    .dependencies = .{
        // zap v0.6.0
        .zap = .{
            .url = "https://github.com/zigzap/zap/archive/refs/tags/v0.6.0.tar.gz",
            .hash = "1220a5a1e6b18fa384d8a98e5d5a25720ddadbcfed01da2e4ca55c7cfb3dc1caa62a",
        }
    }
}

Then, in your build.zig's build function, add the following before exe.install():

    const zap = b.dependency("zap", .{
        .target = target,
        .optimize = optimize,
    });
    exe.addModule("zap", zap.module("zap"));
    exe.linkLibrary(zap.artifact("facil.io"));

Release v0.5.1

24 Feb 15:15
Compare
Choose a tag to compare
Release v0.5.1 Pre-release
Pre-release

ZAP Release v0.5.1

Updates

Request.methodAsEnum() and Windows build error message

This is a small update of recent PRs. Thanks for the great contributions!

See the changelog below for individual contributions.

  • zap.Request.methodAsEnum() returns HTTP method as enum or .UNKNOWN
    • the reason the method is not an enum by default is to avoid the
      string comparisons on every request when we might not need them
  • build attempts on Windows now produce a meaningful error message
  • zap.Request now supports getParamSlice() and getParamSlices()
    which return optional string slices of the raw query string.
    • PRO: no allocation
    • CON: no decoding: "hello+zap" will not be decoded into "hello zap"
    • if you need decoding, you can still use getParamStr().

I updated the docs and zig-0.12.0 branch, too, as with all recent and future releases.

Changelog in alphabetical order:

Froxcey (4):
Use std.http.Method for Request.method
Use custom method enum
Provide Windows error message
Use debug.err and exit 1 for windows fail message

Joe Liotta (1):
fixed unneeded optional unwrap in hello_json

Rene Schallner (8):
Update README.md to point out even more prominently the zig master situation
Merge pull request #72 from Chiissu/master
Merge pull request #75 from Chiissu/windows-errmsg
access raw query params w/o allocator, close #40
cosmetics
Merge pull request #79 from joeypas/master
fix workflow to detect failing builds of individual samples
in http.methodToEnum use std.meta.stringToEnum
performance: revert r.method enum back to ?[]const u8
(new http.Method enum is available via r.methodAsEnum())
use methodAsEnum() in Endpoint, and in json example

Using it

To use in your own projects, put this dependency into your build.zig.zon:

        // zap v0.5.1
        .zap = .{
            .url = "https://github.com/zigzap/zap/archive/refs/tags/v0.5.1.tar.gz",
            .hash = "1220d4802fb09d4e99c0e7265f90d6f3cfdc3e5e31c1b05f0924ee2dd26d9d6dbbf4",
        }

Here is a complete build.zig.zon example:

.{
    .name = "My example project",
    .version = "0.0.1",

    .dependencies = .{
        // zap v0.5.1
        .zap = .{
            .url = "https://github.com/zigzap/zap/archive/refs/tags/v0.5.1.tar.gz",
            .hash = "1220d4802fb09d4e99c0e7265f90d6f3cfdc3e5e31c1b05f0924ee2dd26d9d6dbbf4",
        }
    }
}

Then, in your build.zig's build function, add the following before exe.install():

    const zap = b.dependency("zap", .{
        .target = target,
        .optimize = optimize,
    });
    exe.addModule("zap", zap.module("zap"));
    exe.linkLibrary(zap.artifact("facil.io"));

Release v0.5.0

24 Jan 22:05
Compare
Choose a tag to compare
Release v0.5.0 Pre-release
Pre-release

ZAP Release v0.5.0

Updates

Introducing: zap.Router

Thanks to StringNick, we now have zap.Router with handler closures support!

See the simple_router example. zap.Router is missing doc comments, so if anyone wants to step up, please feel free to send a PR against the zig-0.12.0 my way.

BTW: Documentation (built on zig-0.12.0 branch) is now live at: https://zigzap.org/zap

Doc update PRs are welcome. I am especially excited about the guides feature: https://zigzap.org/zap/#G;

Introduced:

  • zap.Router: the router itself
  • `zap.RequestHandler : a nice way to capture "self" pointers of containers of request functions.
  • simple_router: example demonstrating the above

Thanks again to StringNick!

I updated the zig-0.12.0 branch, too, as with all recent and future releases.

Using it

To use in your own projects, put this dependency into your build.zig.zon:

        // zap v0.5.0
        .zap = .{
            .url = "https://github.com/zigzap/zap/archive/refs/tags/v0.5.0.tar.gz",
            .hash = "1220aabff84ad1d800f5657d6a49cb90dab3799765811ada27faf527be45dd315a4d",
        }

Here is a complete build.zig.zon example:

.{
    .name = "My example project",
    .version = "0.0.1",

    .dependencies = .{
        // zap v0.5.0
        .zap = .{
            .url = "https://github.com/zigzap/zap/archive/refs/tags/v0.5.0.tar.gz",
            .hash = "1220aabff84ad1d800f5657d6a49cb90dab3799765811ada27faf527be45dd315a4d",
        }
    }
}

Then, in your build.zig's build function, add the following before exe.install():

    const zap = b.dependency("zap", .{
        .target = target,
        .optimize = optimize,
    });
    exe.addModule("zap", zap.module("zap"));
    exe.linkLibrary(zap.artifact("facil.io"));

Release v0.4.0

10 Jan 14:37
Compare
Choose a tag to compare
Release v0.4.0 Pre-release
Pre-release

ZAP Release v0.4.0

Updates

Breaking API Cleanup

Documentation (built on zig-0.12.0 branch) is now live at: https://zigzap.org/zap

Doc update PRs are welcome. I am especially excited about the guides feature: https://zigzap.org/zap/#G;

So, I spent a few days with a first pass of cleaning up Zap's API, informed by using it in production for over half a year now.

Refactored:

  • no more type names starting with Simple.
    • zap.SimpleEndpoint -> zap.Endpoint
    • zap.SimpleRequest -> zap.Request
    • zap.SimpleHttpListener -> zap.HttpListener
    • ...
  • zap.Endpoint : zap.Endpoint, zap.Endpoint.Authenticating
    • zap.Endpoint.Listener.register() // was: zap.EndpointListener.addEndpoint
  • zap.Auth : zap.Auth.Basic, zap.Auth.BearerSingle, ...
  • zap.Mustache : stayed the same
  • zap.Request : refactored into its own file, along with supporting types and functions (e.g. http params related)
    • added setContentTypeFromFilename thx @hauleth.
  • zap.Middleware: no more MixContexts
    • (zig structs are fine)
    • check example
  • zap.fio : facilio C FFI stuff does not pollute zap namespace anymore
    • it is still available via zap.fio.
  • allocators are always first-ish param: either first or after self
  • more docstrings

All examples and tests have been updated. Also, check out the documentation (work in progress).

Using it

To use in your own projects, put this dependency into your build.zig.zon:

        // zap v0.4.0
        .zap = .{
            .url = "https://github.com/zigzap/zap/archive/refs/tags/v0.4.0.tar.gz",
            .hash = "1220a20e883195793cff0f298d647d35f675ad25e6556fe75b9ccabc98a349cbf082",
        }

Here is a complete build.zig.zon example:

.{
    .name = "My example project",
    .version = "0.0.1",

    .dependencies = .{
        // zap v0.4.0
        .zap = .{
            .url = "https://github.com/zigzap/zap/archive/refs/tags/v0.4.0.tar.gz",
            .hash = "1220a20e883195793cff0f298d647d35f675ad25e6556fe75b9ccabc98a349cbf082",
        }
    }
}

Then, in your build.zig's build function, add the following before exe.install():

    const zap = b.dependency("zap", .{
        .target = target,
        .optimize = optimize,
    });
    exe.addModule("zap", zap.module("zap"));
    exe.linkLibrary(zap.artifact("facil.io"));

Release v0.3.0

07 Jan 22:04
Compare
Choose a tag to compare
Release v0.3.0 Pre-release
Pre-release

ZAP Release v0.3.0

Updates

-Dopenssl is back && breaking mustache changes

Thanks to @Vemahk, -Dopenssl=true is back! Apparently, while trying to pass user-defined options from a dependent project to zap, I typoed the working solution, and several people pointed out to me that it's as simple as:

    const zap = b.dependency("zap", .{
        .target = target,
        .optimize = optimize,
        .openssl = false, // set to true to enable TLS support
    });

As a result, we re-introduced -Dopenssl, use it if present, and fall back to the ZAP_USE_OPENSSL env var (set to true to enable) if not.

Aaand: thanks to @chooky (BrookJeynes on GH), we have a new, clean, zig-iomatic, documented Mustache API in Zap now:

    var mustache = try Mustache.fromData("{{some_item}} {{& nested.item }}");
    defer mustache.deinit();

    const b = mustache.build(.{
        .some_item = 42,
        .nested = .{
            .item = 69,
        },
    });
    defer b.deinit();

    if(b.str()) |s| {
        std.debug.print("{s}", .{s});
    };

Checkout mustache.zig and the mustache example to learn more.

Using it

To use in your own projects, put this dependency into your build.zig.zon:

        // zap v0.3.0
        .zap = .{
            .url = "https://github.com/zigzap/zap/archive/refs/tags/v0.3.0.tar.gz",
            .hash = "1220697520f1fc8c511db31bb99d3adae035b83abbc9752de59c3a5ac4f22e7a90fa",
        }

Here is a complete build.zig.zon example:

.{
    .name = "My example project",
    .version = "0.0.1",

    .dependencies = .{
        // zap v0.3.0
        .zap = .{
            .url = "https://github.com/zigzap/zap/archive/refs/tags/v0.3.0.tar.gz",
            .hash = "1220697520f1fc8c511db31bb99d3adae035b83abbc9752de59c3a5ac4f22e7a90fa",
        }
    }
}

Then, in your build.zig's build function, add the following before exe.install():

    const zap = b.dependency("zap", .{
        .target = target,
        .optimize = optimize,
    });
    exe.addModule("zap", zap.module("zap"));
    exe.linkLibrary(zap.artifact("facil.io"));

Release v0.2.6

05 Jan 13:11
Compare
Choose a tag to compare
Release v0.2.6 Pre-release
Pre-release

ZAP Release v0.2.6

Updates

TLS / HTTPS / openssl build change!!!

Previously, zap required -Dopenssl=true to build openssl support. Turns out, for projects using zap, it's insanely hard if not impossible to pass the user provided option openssl=true down to the zap dependency.

As a workaround, I changed the build so that it now expects an environment variable ZAP_USE_OPENSSL be set to true.

So, to build the https example, run:

ZAP_USE_OPENSSL=true zig build run-https

The Example

Create the certificate and key file:

$ openssl req -x509 -nodes -days 365 -sha256 -newkey rsa:2048 -keyout mykey.pem -out mycert.pem

Build / run the example

$ ZAP_USE_OPENSSL=true zig build https
$ ZAP_USE_OPENSSL=true zig build -Dopenssl=true run-https

Issue an HTTPS request:

$ curl -v -k https://localhost:4443/build.zig

Using openssl in your code is super simple:

    const tls = zap.fio_tls_new(
        "localhost:4443",
        CERT_FILE,
        KEY_FILE,
        null, // key file is not password-protected
    );
    defer tls.deinit();

That tls data is then passed to the SimpleHttpListener:

    var listener = zap.SimpleHttpListener.init(.{
        .port = 4443,
        .on_request = on_request_verbose,
        .log = true,
        .max_clients = 100000,
        .tls = tls,   //   <----- h e r e
    });
    try listener.listen();

Using it

To use in your own projects, put this dependency into your build.zig.zon:

        // zap v0.2.6
        .zap = .{
            .url = "https://github.com/zigzap/zap/archive/refs/tags/v0.2.6.tar.gz",
            .hash = "1220140b2cdb01223ebd9c8d9f978df8a4b5c50b75f2170ed6af4cb477374511b8eb",
        }

Here is a complete build.zig.zon example:

.{
    .name = "My example project",
    .version = "0.0.1",

    .dependencies = .{
        // zap v0.2.6
        .zap = .{
            .url = "https://github.com/zigzap/zap/archive/refs/tags/v0.2.6.tar.gz",
            .hash = "1220140b2cdb01223ebd9c8d9f978df8a4b5c50b75f2170ed6af4cb477374511b8eb",
        }
    }
}

Then, in your build.zig's build function, add the following before exe.install():

    const zap = b.dependency("zap", .{
        .target = target,
        .optimize = optimize,
    });
    exe.addModule("zap", zap.module("zap"));
    exe.linkLibrary(zap.artifact("facil.io"));

Release v0.2.5

31 Dec 00:42
Compare
Choose a tag to compare
Release v0.2.5 Pre-release
Pre-release

ZAP Release v0.2.5

Updates

Community PR update: HTTP options support!

Hey, things are moving rapidly in ZAP land these days. StringNick (on GitHub) provided a PR adding HTTP options support!

Many thanks for the great PR!

BTW: New stuff is cooking in the 0.12.0 branch. Check out @chooky 's new mustache ;-). Maybe even in the API docs?
(zig build run-docserver is your friend)

Using it

To use in your own projects, put this dependency into your build.zig.zon:

        // zap v0.2.5
        .zap = .{
            .url = "https://github.com/zigzap/zap/archive/refs/tags/v0.2.5.tar.gz",
            .hash = "1220c33e0ecc01b862ff6d929a948f5a8b5526a66f8d883a6d10eaff1620b8d4d605",
        }

Here is a complete build.zig.zon example:

.{
    .name = "My example project",
    .version = "0.0.1",

    .dependencies = .{
        // zap v0.2.5
        .zap = .{
            .url = "https://github.com/zigzap/zap/archive/refs/tags/v0.2.5.tar.gz",
            .hash = "1220c33e0ecc01b862ff6d929a948f5a8b5526a66f8d883a6d10eaff1620b8d4d605",
        }
    }
}

Then, in your build.zig's build function, add the following before exe.install():

    const zap = b.dependency("zap", .{
        .target = target,
        .optimize = optimize,
    });
    exe.addModule("zap", zap.module("zap"));
    exe.linkLibrary(zap.artifact("facil.io"));

Release v0.2.4

30 Dec 12:17
Compare
Choose a tag to compare
Release v0.2.4 Pre-release
Pre-release

ZAP Release v0.2.4

Updates

FIX tls.zig

In the heat of the action, I forgot to add tls.zig in 0.2.3. Ooops.

It's present in 0.2.4

Using it

To use in your own projects, put this dependency into your build.zig.zon:

        // zap v0.2.4
        .zap = .{
            .url = "https://github.com/zigzap/zap/archive/refs/tags/v0.2.4.tar.gz",
            .hash = "1220b22285fd80b8e027bf877a1f66833934b8639cc4fc38c84fbbbcee5b2d6f6a8f",
        }

Here is a complete build.zig.zon example:

.{
    .name = "My example project",
    .version = "0.0.1",

    .dependencies = .{
        // zap v0.2.4
        .zap = .{
            .url = "https://github.com/zigzap/zap/archive/refs/tags/v0.2.4.tar.gz",
            .hash = "1220b22285fd80b8e027bf877a1f66833934b8639cc4fc38c84fbbbcee5b2d6f6a8f",
        }
    }
}

Then, in your build.zig's build function, add the following before exe.install():

    const zap = b.dependency("zap", .{
        .target = target,
        .optimize = optimize,
    });
    exe.addModule("zap", zap.module("zap"));
    exe.linkLibrary(zap.artifact("facil.io"));

Release v0.2.3

30 Dec 02:54
Compare
Choose a tag to compare
Release v0.2.3 Pre-release
Pre-release

ZAP Release v0.2.3

Updates

Refactored zap.Tls

I refactored zap.Tls to make it more zig-like:

    // this is more zig-like:
    const tls = try zap.Tls.init(.{
        .server_name = "localhost:4443",
        .public_certificate_file = CERT_FILE,
        .private_key_file = KEY_FILE,
    });
    // this, too
    defer tls.deinit();

    var listener = zap.SimpleHttpListener.init(.{
        .port = 4443,
        .on_request = on_request_verbose,
        .log = true,
        .max_clients = 100000,
        .tls = tls,
    });
    try listener.listen();

More dangerous refactorings are going to happen in the zig-0.12.0 branch, and being back-ported to master if it makes sense.

Using it

To use in your own projects, put this dependency into your build.zig.zon:

        // zap v0.2.3
        .zap = .{
            .url = "https://github.com/zigzap/zap/archive/refs/tags/v0.2.3.tar.gz",
            .hash = "1220f8764604db85c5e598a5157f1ac21e6410e941f97e6943cddc2c9d9e12794aec",
        }

Here is a complete build.zig.zon example:

.{
    .name = "My example project",
    .version = "0.0.1",

    .dependencies = .{
        // zap v0.2.3
        .zap = .{
            .url = "https://github.com/zigzap/zap/archive/refs/tags/v0.2.3.tar.gz",
            .hash = "1220f8764604db85c5e598a5157f1ac21e6410e941f97e6943cddc2c9d9e12794aec",
        }
    }
}

Then, in your build.zig's build function, add the following before exe.install():

    const zap = b.dependency("zap", .{
        .target = target,
        .optimize = optimize,
    });
    exe.addModule("zap", zap.module("zap"));
    exe.linkLibrary(zap.artifact("facil.io"));