Skip to content

uapi: add new package - #30752

Open
raspbeguy wants to merge 1 commit into
openwrt:masterfrom
raspbeguy:uapi
Open

raspbeguy wants to merge 1 commit into
openwrt:masterfrom
raspbeguy:uapi

Conversation

@raspbeguy

@raspbeguy raspbeguy commented Oct 11, 2026 •

Copy link
Copy Markdown

📦 Package Details

Maintainer: @raspbeguy

Description:

uapi is an HTTP REST API for OpenWrt, written in ucode. It runs inside uhttpd as a ucode handler, with no daemon of its own, and translates REST calls into uci and ubus operations, as a backend for Infrastructure-as-Code tools such as Terraform. It serves curated endpoints under /api/v4/, a raw uci passthrough, and an OpenAPI document that describes them.

This PR now packages 4.1.0, as discussed above. uapi 4.x needs netifd e97e36f (openwrt-iac/uapi#370), so the package depends on netifd (>=2026.07.17), the date of that commit. OpenWrt 25.12 does not carry it.

The uci-defaults script and the template of the token store are in files/. The postinst restarts uhttpd, because uhttpd-mod-ucode compiles the handler only at startup. The build installs the OpenAPI document without whitespace, with tools/compact_json.py from the source archive.

Companion PRs: unbound-uci-ext in #30753, and the LuCI app in openwrt/luci#9128.

The Makefile, the files, the commit message and this description were drafted with an LLM. I reviewed them and ran the tests below.


🔬 Run Testing Details

  • OpenWrt Version: SNAPSHOT r38521-0e66e1c745
  • OpenWrt Target/Subtarget: x86/64
  • OpenWrt Device: QEMU virtual machine

Built in the x86_64 SDK of 25.12.4 from the v4.0.0 tag archive. The APK holds the same files, with the same modes and contents, as the project's 4.0.0 APK. On the device:

  • A fresh install mounted the handler at /api/v4 and created /etc/config/uapi with mode 0600. GET /api/v4/healthz answered 4.0.0.
  • test.sh and test-version.sh passed, and an authenticated GET /api/v4/system answered.
  • An install over a stale /api/v3 mount left only the /api/v4 mount.
  • apk del uapi removed the mount and kept /etc/config/uapi.

4.1.0 changes only the version of the sources. PKG_HASH matches the codeload tarball of the v4.1.0 tag (sha256 checked twice, same content as the tag). It builds in the same SDK from the v4.1.0 archive, and its APK holds the same files, with the same modes and contents, as the project's 4.1.0 APK. On the same device, the APK of this PR installed after apk del uapi, which kept /etc/config/uapi. test.sh and test-version.sh passed, GET /api/v4/healthz answered 4.1.0, and authenticated reads of /api/v4/system and /api/v4/dhcp/cnames answered 200.


✅ Formalities

  • I have reviewed the contributing guidelines.
  • I have reviewed the AI policy.
    • I have used AI or LLM in my pull request, description, or commit
      messages, and the description says what it was used for.

If your PR contains a patch:

Not applicable: the package carries no patches.

Comment thread admin/uapi/Makefile Resolved

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 new commits; no new issues found.


Generated by Claude Code

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 new commits; no new issues found.


Generated by Claude Code

@feckert feckert left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid I don't quite understand why this has to be compiled at startup. Can't that happen during the build process?
Or am I missing something here?

Regardless of my comments, Thanks for building the RESET API—nice work 👍

I'll give it a try right away.

Comment thread admin/uapi/Makefile Resolved
Comment thread admin/uapi/Makefile Resolved
@raspbeguy

Copy link
Copy Markdown
Author

The compile cannot happen in the build. uhttpd does it, at its own startup.

When uhttpd starts, the plugin uhttpd-mod-ucode reads the handler source file and compiles it inside the uhttpd process (ucode.c: uh_ucode_state_init() calls uc_source_new_file(), then uc_compile()). It keeps the compiled VM in memory for the life of the process, and each request forks from it.

ucode_prefix takes a path to a source file only. The module cannot load a precompiled file. So this step cannot move into the build.

This is also why the postinst restarts uhttpd. On an upgrade, the .uc files change on disk, but uhttpd keeps the code that it compiled at startup. A reload does not read the handler again, so only a restart loads the new code. The enabled guard keeps a disabled uhttpd stopped.

@raspbeguy

Copy link
Copy Markdown
Author

Updated to 3.3.0, released today: the version, the ucode-mod-io dependency (a request body that has not arrived in full 10 s after the request answers 400, instead of holding the request process until the script timeout of uhttpd), and the token-store template at /usr/share/uapi/config.template instead of the shipped /etc/config/uapi, which an upgrade always wrote back as .apk-new. The postinst and prerm guards stay as they are.

Comment thread admin/uapi/Makefile Resolved

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 new commits; no new issues found.


Generated by Claude Code

Comment thread admin/uapi/Makefile Resolved
@raspbeguy

Copy link
Copy Markdown
Author

Also, I'm currently working on v4 of uapi, which will be breaking and not compatible with the future old stable (and v3 won't work with new stable), because of the changes that will be part of next openwrt stable (netifd changes mostly). v4 is currently built and checked against the main branch. I wish the v4 release to be included in next openwrt stable, do you think there is a chance it happens?

@feckert

feckert commented Nov 13, 2026

Copy link
Copy Markdown
Member

I'm evaluating it right now. But first I need to get an overview. I don't see any problem at the moment unless there's one I'm missing.

@feckert

feckert commented Nov 17, 2026

Copy link
Copy Markdown
Member

@raspbeguy My initial tests with this version have been successful so far. I haven't tried everything yet, but what I've seen looks nice. Thank you for sharing this with the community.

What does your timeline look like now. Should we still wait for version 3.4.0?
Please also note the new IA policy from OpenWRT.

Just a side note:

  • Your summaries are very detailed. Could you please instruct the AI not to write novels, but to stick to the essentials?
  • I also noticed that the lines in the Markdown files in your repo are pretty long. I had trouble getting my editor to display them properly. My Markdown linter is also flagging them. It would be great if you could adjust that, too.

@raspbeguy

Copy link
Copy Markdown
Author

About the description that are too longs and the line wraps, do you suggest to fix it for future work or also the existing ?

I can update my PR to 3.4.0 for sure, but as I explained I am planning to make the 4.0.0 for next openwrt major. Do you think I should release it earlier so we're sure it will be included then?

Comment thread admin/uapi/Makefile Resolved
Comment thread admin/uapi/Makefile Resolved
Comment thread admin/uapi/Makefile Outdated
$(INSTALL_BIN) $(PKG_BUILD_DIR)/cli/uapi-token $(1)/usr/bin/

$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_CONF) $(PKG_BUILD_DIR)/files/etc/config/uapi $(1)/etc/config/

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default UCI config comes from the upstream source archive; CONTRIBUTING.md asks for OpenWrt integration files to live in admin/uapi/files/ and be installed from there, since openwrt-iac/uapi is not hosted by OpenWrt. The same applies to 99-uapi on line 67.


Generated by Claude Code

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raspbeguy That's an important point that was added recently. I almost overlooked it.

@feckert

feckert commented Nov 18, 2026

Copy link
Copy Markdown
Member

About the description that are too longs and the line wraps, do you suggest to fix it for future work or also the existing ?

The current versions have already been released. So that was just a suggestion on my part that this could perhaps be improved in future UAPI versions. In my editor, I always see MD013/line-length Line length .... warnings. There are several reasons why it has become clear that 80 characters should be the limit. These are the ones that come to mind off the top of my head.

  • In typography, about 50 to 75 characters per line are considered comfortable to read. With longer lines, the eye has a harder time finding the start of the next line.
  • Code is read far more often than it is written. Short lines can be skimmed from top to bottom without scrolling horizontally.

I can update my PR to 3.4.0 for sure, but as I explained I am planning to make the 4.0.0 for next openwrt major. Do you think I should release it earlier so we're sure it will be included then?

This naturally raises a question about the future. Shouldn't we support multiple versions for example v2, v3, or the upcoming v4? Maybe there will even be a v5 at some point? I'm thinking about the API users. . They'll have to adapt their APIs every time, too. I've been experimenting with v3. If I use this version now, I'll have to adapt my code again when v4 comes out.

Therefore, you should consider whether it might make sense to install the different versions side by side. You'll just have to decide on a case-by-case basis which version you need.

@raspbeguy

Copy link
Copy Markdown
Author

v3 only runs on the current OpenWrt major and v4 only on the next one (the netifd changes), so one firmware never runs both. Each OpenWrt release should ship the one uapi major that matches it, mounted at its versioned path (/api/v3 today, /api/v4 with the next major), and clients pin that path. I write a migration guide between all major.

So I do not plan side-by-side installs because this is literally impossible (at least between v3 and v4). I know this might be tedious but that's the same for all programs that are upgraded with breaking changes when upgrading openwrt major.

@feckert

feckert commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Thanks for the explanation! Do I understand correctly that v3 no longer works with newer OpenWrt versions, so v4 is the only option? That doesn’t quite add up for me, so please correct me if I’m missing something.

We could build both packages: if v4 needs new features from netifd master, it would only run on the latest OpenWrt, but v3 should keep working there too. Which netifd changes are we talking about? Installing both at once doesn’t need to be possible; users would just pick one.

I understand the effort of maintaining several versions in parallel, and every version reaches EOL eventually. But as long as nothing technical speaks against it, I’d like to keep v3 usable for now, because this version would then also run on openwert-25.12, which is the current stable release. Downstream projects using the old API would otherwise have to switch immediately, even though v3 still works fine. A gradual move to v4 would make things much easier for the community. I'm not concerned with this first phase of integration. I'm thinking further ahead into the future.

Comment thread admin/uapi/Makefile Resolved
@raspbeguy

Copy link
Copy Markdown
Author

Hello @feckert, sorry for the delay. It was an intense week.

I was certain that V4 couldn't work on 25.12. Turns out, it can. I just tested it. That changes my plans, sorry for the confusion.

I'll release V4 very soon, which still has breaking changes. That way, v3 won't be included in official repos so we don't need to package it. The first officially packaged uapi will be V4. From there, I'll maintain the major uapi versions that are included in the major openwrt releases that are still supported.

Does that sound like a plan for you?

@feckert

feckert commented Nov 22, 2026

Copy link
Copy Markdown
Member

Hello @feckert, sorry for the delay. It was an intense week.

No problem; that happens to me, too.

I was certain that V4 couldn't work on 25.12. Turns out, it can. I just tested it. That changes my plans, sorry for the confusion.

That sounds good

I'll release V4 very soon, which still has breaking changes. That way, v3 won't be included in official repos so we don't need to package it. The first officially packaged uapi will be V4. From there, I'll maintain the major uapi versions that are included in the major openwrt releases that are still supported.

We'd be happy to do it that way.

Does that sound like a plan for you?

There's just one thing you need to clarify. When a new version is released for example v5, do you want to overwrite the old v4 one right away so that we only have one UAPI version in the system, or do you want to create a new package v5 and then delete the old v4 one after a migration period?

@raspbeguy

raspbeguy commented Nov 22, 2026 •

Copy link
Copy Markdown
Author

I'd rather not have multiple packages.

An OpenWrt major will keep the uapi major release it was shipped with. That's why I'll still support this major and periodically release patches, and if OpenWrt package policy enables it, minor releases with new non-breaking features. So an OpenWrt user can rest assured that there won't be any breaking change on uapi when staying in an OpenWrt major.

I consider that, if a user switches to a newer OpenWrt major, they will do the work of preparing their migration path through all the packages they are using. That includes uapi, if a new uapi major has been released in the meantime. If they need time to adapt their use after the OpenWrt release, that's fine but they will need to stay on the old stable until they are ready. uapi announces in patches and minor releases most of the breaking changes and obsolete features that will happen in the next major, or at least in the main branch, so users can totally get ready even before the major release.

Also I am confident that uapi has reached a cruise feature velocity and won't need as frequent major updates as it used to.

Does that make sense to you?

@raspbeguy

raspbeguy commented Nov 22, 2026 •

Copy link
Copy Markdown
Author

Ok so I knew there was something about v4 requiring a new netifd behaviour. I found it when cleaning my issue tracker and just implemented it. so yeah V4 will be only running on the new openwrt release. Which makes me wonder: if a package gets accepted, will it be added in current stable feed ? If so then I should start by packaging v3 or wait for next openwrt major to package v4.

EDIT: got my answer by reading the doc. So as I understand it the package will not be included until next stable which is good news for me.

@feckert

feckert commented Nov 23, 2026

Copy link
Copy Markdown
Member

From my perspective, there's no reason not to switch to v4 right away 👍. Are you done with v4 yet? Because the way I see it, it won't be long before a new stable branch of OpenWRT comes out. We don't have months anymore.

Just to clarify: v3 still works in the master branch with the new netifd feature.
Can you send me a link so I can see what you mean? Then I can check if it's included in the netifd master branch version already.

FYI: The netifd version is occasionally updated to a new version in a stable release too. But you shouldn’t count on that.

@raspbeguy

raspbeguy commented Nov 23, 2026 •

Copy link
Copy Markdown
Author

I'm not sure if v3 will work with main but that doesn't matter, I'm done working on it, I will hopefully release V4 tonight and correct the package PR right after.

And also I will open another package PR for a facultative companion package for uapi, which enables uci to encode an additional unbound config file (which is sourced in the vanilla openwrt config but only editable by hand by default).

EDIT: nevermind, I've already created it: #30753

@raspbeguy

Copy link
Copy Markdown
Author

For information here is the solved issue that leads to the netifd change (witch I contributed myself) that V4 takes advantage of: openwrt-iac/uapi#370

If netifd is updated within a stable and brings changes that breaks uapi, I guess it will need a uapi patch release. Which is acceptable I think.

@raspbeguy
raspbeguy force-pushed the uapi branch 2 times, most recently from 3110198 to 8a8acd5 Compare November 24, 2026 15:38
@raspbeguy

Copy link
Copy Markdown
Author

@feckert v4 is now released. I updated the PR.

So here is the list of the related PRs:

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 new commits; no new issues found.


Generated by Claude Code

@raspbeguy

raspbeguy commented Nov 29, 2026 •

Copy link
Copy Markdown
Author

Since I announced 4.0 and the good chance of uapi being in the next OpenWrt release, I received a feature contribution and made a few changes of my own, all already merged in main. Only then did I realize that I needed a new git workflow, with a maintenance branch for the minor that an OpenWrt release ships: that minor gets bug and security fixes for as long as the release is supported. I also decided on a minor cadence of one month.

So I will probably do an exceptional 4.1.0 release at the start of December to settle this, and update this PR to it. I'll post a call for contributions on the forum, to include as many features as possible before the next OpenWrt release branches.

If it's too late and only 4.0 is included, that's ok, I'll figure out something else.

@feckert

feckert commented Dec 1, 2026

Copy link
Copy Markdown
Member

Since I announced 4.0 and the good chance of uapi being in the next OpenWrt release, I received a feature contribution and made a few changes of my own, all already merged in main. Only then did I realize that I needed a new git workflow, with a maintenance branch for the minor that an OpenWrt release ships: that minor gets bug and security fixes for as long as the release is supported. I also decided on a minor cadence of one month.

We'd be happy to do it that way

So I will probably do an exceptional 4.1.0 release at the start of December to settle this, and update this PR to it. I'll post a call for contributions on the forum, to include as many features as possible before the next OpenWrt release branches.

That means I'm holding off on merging 4.0.0 for now. Just to clarify:
If an API change is needed for example v5, then there will be a major version bump to 5.x.x. If a new feature is added, there will be a 4.1.0 or 5.1.0. If there are bug fixes, there will be a 4.0.1 or 4.1.1, or a 5.0.1 or 5.1.1. Do I understand that correctly? And do you create a new branch for every major release, such as 4.0.0 or 5.0.0?

If it's too late and only 4.0 is included, that's ok, I'll figure out something else.

We can wait a little longer. Just let me know when you're ready for the merge. To keep better track of all the PRs, you can also mark the PR as a draft.

@raspbeguy

Copy link
Copy Markdown
Author

Yes, that is right, with one nuance: a bug fix goes to the latest minor. Once 4.1.0 is out, a fix ships as 4.1.1, and 4.0.x gets no more releases. An older minor keeps getting fixes only when an OpenWrt release ships it.

About branches, there is not one per major, but one per release line:

  • main carries the latest minor and its fixes.
  • next prepares the next minor.
  • When an openwrt-XX.YY branch ships uapi 4.N, I cut release/4.N.x. It gets the bug and security fixes for as long as that OpenWrt release is supported, and I send each of its patches to openwrt-XX.YY here.
  • A new major release is similar to a minor release, except it contains breaking changes.

I will update it to 4.1.0 probably tonight, as we are now in December and I want to stick to my schedule.

uapi is an HTTP REST API for OpenWrt, written in ucode. It runs inside
uhttpd as a ucode handler and translates REST calls into uci and ubus
operations, as a backend for Infrastructure-as-Code tools.

The postinst restarts uhttpd, because uhttpd-mod-ucode compiles the
handler only at startup. The uci-defaults script and the template of
the token store are in files/. The OpenAPI document is installed
without whitespace. uapi 4.x needs netifd e97e36f, so the package
depends on a netifd version from that commit date or later.

Release notes: https://github.com/openwrt-iac/uapi/releases/tag/v4.1.0

Signed-off-by: Guy Godfroy <guy.godfroy@gugod.fr>
@raspbeguy

Copy link
Copy Markdown
Author

@feckert I released 4.1.0. Next minor next month. From my side it good to go. If you merge it and OpenWrt issues a release candidate with this version it'll become a "LTS" version.

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 new commit; no new issues found.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants