GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - tmlbl/zinatra: An HTTP framework for Zig with a familiar API

BranchesTags
Open more actions menu

Latest commit

 

History

58 Commits
58 Commits

Folders and files

NameName
Last commit message
Last commit date
docs
docs
 
 
examples
examples
 
 
src
src
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
build.zig
build.zig
 
 
build.zig.zon
build.zig.zon
 
 

Repository files navigation

Zinatra

Zinatra is an HTTP server framework based on Zig's std.http.Server, with a familiar high-level API.

const std = @import("std");
const zin = @import("zinatra");

// zin.Handler functions accept a *Context and return !void
fn greet(ctx: *zin.Context) !void {
    // params can be accessed via the built-in map
    const name = ctx.params.get("name").?;
    // each context creates an arena allocator, so you can make quick
    // per-request allocations without calling free
    const msg = try std.fmt.allocPrint(ctx.allocator(), "Hello, {s}!", .{name});
    // Context helper methods for common response types
    try ctx.text(msg);
}

// zin.Context provides shortcuts for common cases, like sending JSON
fn sendJson(ctx: *zin.Context) !void {
    try ctx.json(.{
        .foo = "bar",
    });
}

// Middleware functions have the same function signature as route handlers
fn defaultHeaders(ctx: *zin.Context) !void {
    try ctx.headers.append(.{ .name = "server", .value = "zin/v0.1.0" });
}

pub fn main() !void {
    var app = try zin.App.init(.{
        .allocator = std.heap.page_allocator,
    });
    defer app.deinit();

    // optionally add query string parameters to route parameters map
    try app.use(zin.mw.queryStringParser);

    try app.use(defaultHeaders);

    // use classic route templating syntax to register handlers
    try app.get("/greet/:name", greet);

    try app.get("/json", sendJson);

    try app.listen();
}

Check out the examples folder for more functionality.

Perhaps your next "microservice" at work could be in Zig! Think about it...

About

An HTTP framework for Zig with a familiar API

Topics

zig-package

Resources

Readme
MIT license
Activity

Stars

16 stars

Watchers

1 watching

Forks

3 forks
Report repository

Releases

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.