Giter Club home page Giter Club logo

zig-http-test's Introduction

Zig HTTP Server

Made with zig, zap, mustache-zig, htmx, and tailwind.

Purpose

I work mainly in web dev, and I like zig. Thought I'd see how the two went together.

Findings

Yeah. It's pretty aight.

Kinda wish zig had some kind of interface/trait system, but I get by.

I've had to do a lot of legwork to very little website running. I'm hoping with all the work I've put into the backend that I'll get to spend more time developing the website itself, but I have yet to put a whole lot into it.

I really enjoy the level of control C and Zig grant, but I've never liked working in C. Too many quirks with the language, arrays are just pointers and don't preserve length, it's hard to do it right. Zig seems fairly straightforward to do both well and correctly, and it's been surprizingly easy to learn (granted, after many years programming experience behind it).

So far, it's been a very positive experience.

Bugs?

In Zig

I've noticed that if an error occurs behind a duck type (anytype), the stack trace is sometimes destroyed, and it's not possible to tell where an error is occuring. Judging Zig for that it does not have interfaces and relies heavily on duck-typing for polymorphism, this is a huge pain point for working with Zig.

I've also tried and failed to use the built in http client to pull requests from https. The error was very strange and I wasn't able to work through it with the limited amount of time I allocated to it.

In Zap

None, really. Very smooth.

In Mustache-Zig

Haven't had much a chance to mess around with it.

In HTMX

Haven't had much a chance to mess around with it :(.

In my own code

Ha, there are plenty.

I'm keeping a decent track of feature I want and bugs I notice in the Issues tab. Check those out if you're curious. Since this is a personal project, I'm not terribly inclined to tag things, though...

zig-http-test's People

Contributors

vemahk avatar

Stargazers

 avatar

Watchers

 avatar

zig-http-test's Issues

Spice up the build.zig

I don't quiet like the defaults of how the zig builder arranges zig-out. I guess just because of my background in C#, I'm used to different build targets and modes being placed in different sub-folders in the build-out directory, but I kind of miss it.

When zig builds my project, I want it to place it in the ./zig-out/<build_mode>/<target> directory.

Allow for Resource IDs in endpoint path

e.g. /path/to/resource/5.

Minimum Required: allow for u64 identifiers at the end of the path.

Nice to have: allow it to be anywhere in the path.
Nice to have: support UUIDs.

Reduce inline for in template.zig

Right now, on template render, I have to match the runtime-found identifier name in the template to the compile-known field name using a bunch of inline for's.

We theoretically could do this only once on template compile by using a single inline for to find the field index, then we can store the field name index in the Template or DeconstructedHtml and use it to look up the compile-time field name for accessing the field of the given struct. Right?

Introduce a Persistence Layer

We have some choices, from least annoying to most annoying.

  1. Just use SQLite
  2. SQLite is for babies; write your own file-based, binary, ACID-compliant, persistent storage solution.

I have a wide rage of intellectually diverse ideas, as you can tell.

Add options to rendering with template

To at least disable the automatically-enabled html encoding. Sometimes I want to inject raw html, what can I say?

Also to help specify formatting for floats, because f floats.

Figure out a better way to init and store html templates

Currently, they are stored in their respective struct as a nullable template until the first render call is made. At that time, the template is inited and treated as global (it is never deinited for the life of the program).

This isn't a particularly huge issue, I just kinda don't like the var? vs a const template instance. That, and I don't like never deiniting allocated memory. I guess for all practical purposes, it is just going to live for the life of the application, anyway.

Define template render options at comptime per field

Each template should associate static, comptime RenderOptions with a particular field of its T struct instead of passing in a RenderOptions parameter to the render function at runtime, which affects all fields equally.

Template watch

Modify the templates-from-runtime-file to watch their source file for updates and re-init the template instance when the template is changed.

The most naive implementation I can think of is just to check the file stats every time the get request is made and remember the date we last reloaded the template. If the file has been modified since we created the template, deinit the old template and reinit a new one. We will want to disable this for release builds, probably, because that is time a production application would not need to spend time doing. Right? I feel like hot-reloading is an unnecessary expense in a lot of cases... but what do I know?

TailwindCSS

Whenever I feel like actually doing web-dev.

Allow for comptime template initialization

Following work on #6, the Template is in a decent spot to evolve into using comptime. I have some investigation I need to do in order to see if this will work, however.

The Template.init() requires an allocator. There are a few reasons for this.

  • First is that .{field_markers} could use Zig's string iteral field, such as @"this". All's well that ends well, but it can contain escape characters, which modify the true presentation of the field name, thus I need an allocator to allow for the extracting of the true field name.
  • I also need space to cut out the .{field_markers} from the original template text into the new text.
  • I also need space to allocate the FieldMarkers.

One possible solution is to use a std.heap.FixedBufferAllocator. Comptime restricts the existence of syscalls during comptime, but the fixed buffer allocator may be able to just use stack space available during comptime. I am not, however, sure of comptime's restrictions that may inhibit the total possible size of templates using this strategy. I am also not certain whether I can arrange two arrays of disparate types in such a way that comptime will accept.

Alternatively, I could compromise on the valid template syntax to not allow escape characters, thus reducing my need for the allocator. This does make the set of possible identifiers in the template language a subset of Zig's possible identifiers, but who really needs freaky field names, anyway?

Might end up scrapping this one. Not sure how much of a problem it will actually be.

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.