GithubHelp home page GithubHelp logo

vemahk / zig-http-test Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 145 KB

A toy webserver, built with Zig, Zap, HTMX, and TailwindCSS

License: MIT License

Zig 85.19% HTML 5.57% JavaScript 7.15% CSS 2.10%
htmx webserver zap zig

zig-http-test's People

Contributors

vemahk avatar

Stargazers

 avatar

Watchers

 avatar

zig-http-test's Issues

TailwindCSS

Whenever I feel like actually doing web-dev.

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.

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?

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.

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.

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?

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.

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.

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.

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.