Home
Help
Search
Login
Register
OPNsense Forum
»
English Forums
»
Development and Code Review
(Moderator:
fabian
) »
API Response Objects
« previous
next »
Print
Pages: [
1
]
Author
Topic: API Response Objects (Read 2572 times)
lattera
Full Member
Posts: 207
Karma: 82
API Response Objects
«
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.
Logged
fabian
Moderator
Hero Member
Posts: 2769
Karma: 200
OPNsense Contributor (Language, VPN, Proxy, etc.)
Re: API Response Objects
«
Reply #1 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.
Logged
lattera
Full Member
Posts: 207
Karma: 82
Re: API Response Objects
«
Reply #2 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.
Logged
Print
Pages: [
1
]
« previous
next »
OPNsense Forum
»
English Forums
»
Development and Code Review
(Moderator:
fabian
) »
API Response Objects