Giter VIP home page Giter VIP logo

apple_pie's Introduction

Apple Pie

Apple pie is a HTTP Server implementation in Zig. The initial goal is to offer full support for http versions 1.0 and 1.1 with 2.0 and further planned at a later stage. With Apple Pie I'd like to offer a library that contains all features you'd expect from a server, while still remaining performant. Rather than hiding complexity, I want to expose its functionality so users can replace and/or expand upon to fit their needs.

Roadmap

  • HTTP 1.1 spec (fully) implemented

Features

  • Crossplatform support
  • Extensive routing (see the router example) built in
  • Allows for both async and blocking I/O using Zig's std event loop

Example

A very basic implementation would be as follow:

const std = @import("std");
const http = @import("apple_pie");

// use evented mode for event loop support
pub const io_mode = .evented;

// optional root constant to define max stack buffer size per request
pub const buffer_size: usize = 4096;
// optional root constant to define max header size per request
pub const request_buffer_size: usize = 4096;

/// Context variable, accessible by all handlers, allowing to access data objects
/// without requiring them to be global. Thread-safety must be handled by the user.
const Context = struct {
    data: []const u8,
};

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer _ = gpa.deinit();
	
    const my_context: Context = .{ .data = "Hello, world!" };
	
    try http.listenAndServe(
        gpa.allocator(),
        try std.net.Address.parseIp("127.0.0.1", 8080),
        my_context,
        index,
    );
}

fn index(ctx: Context, response: *http.Response, request: http.Request) !void {
    _ = request;
    try response.writer().print("{s}", .{ctx.data});
}

More examples can be found in the examples folder.

Building

Apple Pie is being developed on Zig's master branch and tries to keep up-to-date with its latest development.

To build Apple Pie a simple zig build will suffice.

To build any of the examples, use the following:

zig build example -Dexample=<example_name>

it will appear in zig-out/bin/example_name

apple_pie's People

Contributors

avokadoen avatar bootradev avatar catdevnull avatar g-w1 avatar haze avatar joachimschmidt557 avatar leroycep avatar lun-4 avatar luukdegram avatar marler8997 avatar masterq32 avatar mattnite avatar nektro avatar vrischmann avatar zuyoutoki avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.