Skip to content

Release v0.4.0

Pre-release
Pre-release
Compare
Choose a tag to compare
@github-actions github-actions released this 10 Jan 14:37

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"));