Releases: zigzap/zap
Release v0.9.1
ZAP Release v0.9.1
Updates
Bugfix for Middleware.EnpointHandler checkPath logic
I introduced a bug by wrongly trying to de-morgan the logic.
Thx @andr3h3nriqu3s11 for submitting issue #136 #136
I reverted the commit.
Using it
In your zig project folder (where build.zig
is located), run:
zig fetch --save "git+https://github.com/zigzap/zap#v0.9.1"
Then, in your build.zig
's build
function, add the following before
b.installArtifact(exe)
:
const zap = b.dependency("zap", .{
.target = target,
.optimize = optimize,
.openssl = false, // set to true to enable TLS support
});
exe.root_module.addImport("zap", zap.module("zap"));
Release v0.9.0
ZAP Release v0.9.0
Updates
Small API Refactors
This is a small update from recent PRs with little breaking changes in
zap.Mustache
and zap.Middleware.EndpointHandler
. Thanks for the
great contributions! See the changelog below.
Also: we now use zig fetch!
This greatly simplifies the instructions in the README and release
notes.
Breaking Changes:
Mustache:
- renamed
zap.Mustache.MustacheLoadArgs
tozap.Mustache.LoadArgs
zap.Mustache.BuildResult
is a public type now
Middleware:
zap.Middleware.EndpointHandler
now takes more than one option:
/// Options used to change the behavior of an `EndpointHandler`
pub const EndpointHandlerOptions = struct {
/// If `true`, the handler will stop handing requests down the chain if the
/// endpoint processed the request.
breakOnFinish: bool = true,
/// If `true`, the handler will only execute against requests that match
/// the endpoint's `path` setting.
checkPath: bool = false,
};
I updated the docs and zig-master branch, too.
Changelog:
Rene Schallner (5):
Merge pull request #117 from cosmicboots/mustache-build
doc: getHeader need lowercase keys
Merge pull request #120 from cosmicboots/endpoint-middleware
Merge pull request #127 from iacore/patch-1
docs, announceybot: switch to using zig fetch
Thom Dickson (4):
include BuildResult in public Mustache API
rename MustacheLoadArgs to LoadArgs
Create options for EndpointHandler
update docs and examples for endpoint middleware
iacore (1):
update docs for zap.start
Using it
In your zig project folder (where build.zig
is located), run:
zig fetch --save "git+https://github.com/zigzap/zap#v0.9.0"
Then, in your build.zig
's build
function, add the following before
b.installArtifact(exe)
:
const zap = b.dependency("zap", .{
.target = target,
.optimize = optimize,
.openssl = false, // set to true to enable TLS support
});
exe.root_module.addImport("zap", zap.module("zap"));
Release v0.8.0
ZAP Release v0.8.0
Updates
Update to Zig 0.13
With the help of our awesome contributers, we have a new release:
- Zap is now officially based on Zig 0.13.0!
- Thx to Lois Pearson, we now have
mimetypeRegister
andmimetypeClear
- Thx to geemili, we don't need to link facil.io in our build.zigs anymore
- Thx to SΓΆren Michaels,
methodAsEnum
supports theHEAD
method. - ... and more, see the changelog below
Note: there now is a zig-master
branch that gets updated with breaking changes of Zig master on a somewhat regular basis. Please feel free to send PRs.
Many thanks again to everyone who helped out:
Giuseppe Cesarano (1):
fix: _debug typo in startWithLogging
Joe Koop (1):
update http.zig to rfc9110 using MDN as a reference
Lord Asdi (1):
fix: use std.process.getEnvVarOwned instead of std.posix.getenv
Louis Pearson (8):
fix: last_modifed -> last_modified
fix: docserver: server wasm with correct mimetype
feat: Wrap mimetypeRegister and mimetypeClear
fix: move getHeaderCommon to zap.zig
feat: add parseAccept
feat: make example for parseAccept
fix: simplify accept header api somewhat
feat: pre-allocate enough space for accept items
Michael Wendt (1):
feat: remove deprecated path
Rene Schallner (18):
Update hello_json.zig
fix docserver invocation from build.zig
proposed change to parseAccept API
make zap master build with zig master
update zig version
updated zig-master check in CI
update badge in README
corrected release templates
SΓΆren Michaels (1):
feat: add HEAD Method to methodAsEnum
geemili (1):
feat: streamline depending on zap by linking facil.io to module
Using it
To use in your own projects, put this dependency into your build.zig.zon
:
// zap v0.8.0
.zap = .{
.url = "https://github.com/zigzap/zap/archive/refs/tags/v0.8.0.tar.gz",
.hash = "12209936c3333b53b53edcf453b1670babb9ae8c2197b1ca627c01e72670e20c1a21",
}
Here is a complete build.zig.zon
example:
.{
.name = "My example project",
.version = "0.0.1",
.dependencies = .{
// zap v0.8.0
.zap = .{
.url = "https://github.com/zigzap/zap/archive/refs/tags/v0.8.0.tar.gz",
.hash = "12209936c3333b53b53edcf453b1670babb9ae8c2197b1ca627c01e72670e20c1a21",
},
},
.paths = .{
"",
},
}
Then, in your build.zig
's build
function, add the following before
b.installArtifact(exe)
:
const zap = b.dependency("zap", .{
.target = target,
.optimize = optimize,
.openssl = false, // set to true to enable TLS support
});
exe.root_module.addImport("zap", zap.module("zap"));
Release v0.7.0
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
tozap.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
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
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
- the reason the method is not an enum by default is to avoid the
- build attempts on Windows now produce a meaningful error message
zap.Request
now supportsgetParamSlice()
andgetParamSlices()
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
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
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
.
- it is still available via
- 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
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
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"));