-
Notifications
You must be signed in to change notification settings - Fork 102
Migration
httpz has seen a handful of breaking changes recently. The good news is that httpz.Request and httpz.Response are largely unchanged.
There used to be 3 variations of httpz.Server:
-
httpz.Server()would map tohttpz.ServerCtx(void, void) -
httpz.ServerApp(H) would map tohttpz.ServerCtx(H, H)` httpz.ServerCtx(H, A)
There is now a single version: httpz.Server(H).
If you were using httpz.Server(), you should use httpz.Server(void) , pass void ({}) as the 3rd parameter to init and you're done.
If you were using httpz.ServerApp(H) you should now use http.Server(H), but see the 2nd major change.
If you were using httpz.ServerCtx(H, A) you should now use http.Server(H), but see the 2nd major change.
httpz now infers more from your custom handler (H).
Instead of setting serve.notFound, your Handler should have a public notFound method:
pub fn notFound(_: *Handler, req: *httpz.Request, res: *httpz.Response) !void {}Instead of setting server.errorHandler, your Handler should have a public uncaughtError method:
pub fn uncaughtError(_: *Handler req: *httpz.Request, res: *httpz.Response, err: anyerror) void {Instead of setting server.dispatcher, define a dispatch method:
pub fn dispatch(_: *Handler, action: httpz.Action(*Handler), req: *httpz.Request, res: *httpz.Response) !voidWhat about cases previously using ServerCtx(H, A)? Simply change the action parameter of your dispatch:
pub fn dispatch(_: *Handler, action: httpz.Action(*RequestContext), req: *httpz.Request, res: *httpz.Response) !voidAnyone using the existing handle overload (i.e. for deep integration, like JetZig), should not need to change.
If you were using websocket integration, you should first familiarize yourself with the changes made to it.
From httpz' point of view, your handler must have a WebsocketHandler declaration which is the same type passed to httpz.upgradeWebsocket. I know it's frail, but it's undefined behavior of the two types don't match. (The reason for having to provide the type twice, is to avoid having to make httpz.Response a generic which carries the websocket handler type).
config.websocket has changed, see the readme.
Not only is websocket.zig now nonblocking (on Linux/MacOS/BSD), but the integration with httpz is much tighter.
Previously the router had a "C" variant for each method. For example, there was a router.get and a router.getC. The "C" meant "Config" and was an overload which took a 3rd parameter (the route config). "C" variants have been removed and a config is always expected (an empty config can be specified, e.g. router.get("path", function, .{});
The router.dispatcher() and router.handler() methods are now fields.
The router now supports middleware. See the readme for middlewares.
The res.conn type has changed to from Conn to HTTPConn. There were small changes made to this type, but res.conn.stream is still valid, and it's unlikely anyone was using anything else.
server.dispatchUndefined() is removed.