mirror of
https://github.com/jetzig-framework/jetzig.git
synced 2025-05-14 14:06:08 +00:00

Detect if provided params are a subset of actual params, provide informative errors if not.
26 lines
821 B
Zig
26 lines
821 B
Zig
const std = @import("std");
|
|
const jetzig = @import("jetzig");
|
|
|
|
/// This example demonstrates usage of Jetzig's background jobs.
|
|
pub fn index(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View {
|
|
// Prepare a job using `src/app/jobs/example.zig`.
|
|
var job = try request.job("example");
|
|
|
|
// Add a param `foo` to the job.
|
|
try job.params.put("foo", data.string("bar"));
|
|
try job.params.put("id", data.integer(std.crypto.random.int(u32)));
|
|
|
|
// Schedule the job for background processing.
|
|
try job.schedule();
|
|
|
|
return request.render(.ok);
|
|
}
|
|
|
|
test "index" {
|
|
var app = try jetzig.testing.app(std.testing.allocator, @import("routes"));
|
|
defer app.deinit();
|
|
|
|
const response = try app.request(.GET, "/background_jobs", .{});
|
|
try response.expectJob("example", .{ .foo = "bar" });
|
|
}
|