OPNsense Forum

English Forums => Development and Code Review => Topic started by: lattera on May 03, 2020, 08:45:56 pm

Title: API Response Objects
Post by: lattera on May 03, 2020, 08:45:56 pm
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.
Title: Re: API Response Objects
Post by: fabian on May 03, 2020, 08:57:03 pm
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.
Title: Re: API Response Objects
Post by: lattera on May 03, 2020, 09:07:11 pm
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.