API Response Objects

Started by lattera, May 03, 2020, 08:45:56 PM

Previous topic - Next topic
I've started working on a C-based API library (libopnsenseapi). I've noticed that the API documentation ( https://docs.opnsense.org/development/api.html ) is lacking. I'm looking for a description of the JSON objects that get returned from each API endpoint.

For example, when I call `https://opnsense.local/api/core/firmware/getfirmwareconfig`, what is the JSON object that gets returned to me going to look like? I will need to parse the JSON object in a way that makes sense for that particular API endpoint.

It seems to me that right now, I'll need to enumerate each API endpoint to determine what gets returned. Since some of those endpoints cause config changes, I'm a bit weary of doing that.

edit[0]: accidentally hit the "Save" button before I finished writing this post.

Hi Shawn,

most of the models now use the base methods, which means that you can generate the response object from the model xml definition and the action method.

See: https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Base/ApiMutableModelControllerBase.php

If that convention is used, it is done using the setter convention of the backend field implementation so you can read out of the model, how the result should look like.

I think the problem I'm having is that I don't want to have to grep the OPNsense codebase (`core.git`) to rebuild in my mind what the JSON objects would look like. Doing that would be very prone to error.