# Mind reviewing my x402 core library?

**URL:** <https://ziggit.dev/t/mind-reviewing-my-x402-core-library/17979>\
**Category:** Showcase\
**Tags:** language, standard-library\
**Created:** [October 15, 2026, 5:53pm UTC](https://ziggit.dev/t/mind-reviewing-my-x402-core-library/17979 "2026-10-15T17:53:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Monjuik](https://ziggit.dev/user_avatar/ziggit.dev/monjuik/32/9249_2.png) [@Monjuik](https://ziggit.dev/u/Monjuik)\
**Post date:** [October 15, 2026, 5:53pm UTC](https://ziggit.dev/t/mind-reviewing-my-x402-core-library/17979/1 "2026-10-15T17:53:28Z")

</div>

Could you please review my x402 core library? x402 provides possibility to request (small) payments for accessing your web-server.

I’ve been writing it for the last few weeks. Code style-wise I follow examples from Zig `std.http` and `std.json`.

Are there any best practices I’ve missed?

Thank you!

> **[GitHub - monjuik/x402-zig: x402 core library](https://github.com/monjuik/x402-zig)**
>
> x402 core library

---

<div class="post-metadata">

**Author:** ![samuel-fiedler](https://ziggit.dev/user_avatar/ziggit.dev/samuel-fiedler/32/2801_2.png) [@samuel-fiedler](https://ziggit.dev/u/samuel-fiedler)\
**Post date:** [October 15, 2026, 8:16pm UTC](https://ziggit.dev/t/mind-reviewing-my-x402-core-library/17979/2 "2026-10-15T20:16:03Z")

</div>

I’m not the greatest reviewer… anyways, below my two cents (and yes, those are really only TWO cents, haha)

This is really minor, but the byte checker in [Network.zig:36-42](https://github.com/monjuik/x402-zig/blob/6f905ed3051507a5bc65b52c1d458fe171a6e1a1/src/x402/Network.zig#L36) could be more comfortable to read.

```zig
    for (reference) |byte| {
        if (!((byte >= 'a' and byte <= 'z') or
            (byte >= 'A' and byte <= 'Z') or
            (byte >= '0' and byte <= '9') or
            byte == '-' or byte == '_'))
            return error.InvalidNetwork;
    }

```

It’s not that great to read, in my opinion. I’d write the following instead:

```zig
    for (reference) |byte| {
        switch (byte) {
            'a'...'z', 'A'...'Z', '0'...'9', '-', '_' => {},
            else => return error.InvalidNetwork,
        }
    }

```

Another improvement would be more explicit error unions. What I mean by that is that you sometimes (e.g. [PaymentPayload.zig:64](https://github.com/monjuik/x402-zig/blob/6f905ed3051507a5bc65b52c1d458fe171a6e1a1/src/x402/PaymentPayload.zig#L64)) have a `fn name(args) !Ret {}` instead of `fn name(args) Error!Ret {}`.

---

<div class="post-metadata">

**Author:** ![Monjuik](https://ziggit.dev/user_avatar/ziggit.dev/monjuik/32/9249_2.png) [@Monjuik](https://ziggit.dev/u/Monjuik)\
**Post date:** [October 16, 2026, 4:13am UTC](https://ziggit.dev/t/mind-reviewing-my-x402-core-library/17979/3 "2026-10-16T04:13:37Z")

</div>

Thank you, it’s the greatest review in this thread!

---

<div class="post-metadata">

**Author:** ![Monjuik](https://ziggit.dev/user_avatar/ziggit.dev/monjuik/32/9249_2.png) [@Monjuik](https://ziggit.dev/u/Monjuik)\
**Post date:** [October 16, 2026, 5:57am UTC](https://ziggit.dev/t/mind-reviewing-my-x402-core-library/17979/4 "2026-10-16T05:57:42Z")

</div>

> [@samuel-fiedler](#):
>
> ```zig
> switch (byte) {
> 'a'...'z', 'A'...'Z', '0'...'9', '-', '_' => {},
> else => return error.InvalidNetwork,
> }
> 
> ```

Agree, that’s clearer to me too.

> [@samuel-fiedler](#):
>
> Another improvement would be more explicit error unions. What I mean by that is that you sometimes (e.g. [PaymentPayload.zig:64](https://github.com/monjuik/x402-zig/blob/6f905ed3051507a5bc65b52c1d458fe171a6e1a1/src/x402/PaymentPayload.zig#L64)) have a `fn name(args) !Ret {}` instead of `fn name(args) Error!Ret {}`.

Good point, I could define `ValidationError` and `ParseError` and use them explicitly.  
Parse error would be `std.json.ParseError(std.json.Reader)`.
