-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Commands API version 1 #4118
Commands API version 1 #4118
Conversation
@badlop: Why not v1 to old and v2 to new? |
When commands are initially defined, they don't have any version assigned yet: they are ejabberd/include/ejabberd_commands.hrl Line 53 in b556fae
When a command gets some change that would break its API, then that command should get a new definition. And the version number assigned to that new definition will be = API version included in that ejabberd release. In this sense, when a new ejabberd release includes breaking changes in the API, it will include an API version with increased number. |
Commands that has some argument change: - add_rosteritem - oauth_issue_token - send_direct_invitation - srg_create - subscribe_room - subscribe_room_many
When configured like: listen: - request_handlers: /api: mod_http_api /apizero/v0: mod_http_api What API version will be used depending on the URL: - api/commandname use the latest available version - api/commandname/v0 use version 0 - apizero/v0/commandname use version 0 - apizero/v0/commandname/v2 use version 2
Tuple elements are separated with : List elements are separated with , For example: ejabberdctl add_rosteritem user1 localhost testuser7 localhost NickUser77l gr1,gr2,gr3 both ejabberdctl create_room_with_opts room1 conference.localhost localhost public:false,persistent:true ejabberdctl subscribe_room_many user1@localhost:User1,admin@localhost:Admin room1@conference.localhost urn:xmpp:mucsub:nodes:messages,urn:xmpp:mucsub:nodes:affiliations Affected commands: - add_rosteritem - create_room_with_opts - oauth_issue_token - send_direct_invitation - set_vcard2_multi - srg_create - subscribe_room - subscribe_room_many
This PR includes many improvements in API versioning, mod_http_api, ejabberdctl, and some commands.
Support for API Versioning
Until now, when a new ejabberd release changed some API command (an argument renamed, a result in a different format...), then you had to update your API client to the new API at the same time that you updated ejabberd.
Now the ejabberd API commands can have different versions, by default the most recent one is used, and the API client can specify the API version it supports.
In fact, this feature was implemented seven years ago, included in ejabberd 16.04, documented in ejabberd Docs: API Versioning... but it was never actually used!
This ejabberd release includes many fixes to get API versioning up to date, and it starts being used by several commands.
Let's say that ejabberd 23.10 implemented API version 0, and this ejabberd xx.yy adds API version 1. You may want to update your API client to use the new API version 1... or you can continue using API version 0 and delay API update a few weeks or months.
To continue using API version 0:
--version 0
. For example:ejabberdctl --version 0 get_roster admin localhost
v0
to therequest_handlers
path. For example:/api/v0: mod_http_api
Check the details in ejabberd Docs: API Versioning.
ejabberd Commands API Version 1
When you want to update your API client to support ejabberd API version 1, those are the changes to take into account:
All those changes are described in the next sections.
Commands with list arguments
Several commands now use
list
argument instead of astring
with separators (different commands used different separators:;
:
\\n
,
).The commands improved in API version 1:
add_rosteritem
oauth_issue_token
send_direct_invitation
srg_create
subscribe_room
subscribe_room_many
For example,
srg_create
in API version 0 took as arguments:now in API version 1 the command expects as arguments:
mod_http_api not named results
There was an incoherence in mod_http_api results when they were integer/string and when they were list/tuple/rescode...: the result contained the name, for example:
Staring in API version 1, when result is an integer or a string, it will not contain the result name. This is now coherent with the other result formats (list, tuple, ...) which don't contain the result name either.
Some examples with API version 0 and API version 1:
ejabberdctl with list arguments
ejabberdctl now supports list and tuple arguments, like mod_http_api and ejabberd_xmlrpc. This allows ejabberdctl to execute all the existing commands, even some that were impossible until now like
create_room_with_opts
andset_vcard2_multi
.List elements are separated with
,
and tuple elements are separated with:
.Relevant commands:
add_rosteritem
create_room_with_opts
oauth_issue_token
send_direct_invitation
set_vcard2_multi
srg_create
subscribe_room
subscribe_room_many
Some example uses:
ejabberdctl list results
Until now, ejabberdctl returned list elements separated with
;
. Now in API version 1 list elements are separated with,
.For example, in ejabberd 23.10:
Since this ejabberd release, using API version 1:
it is still possible to get the results in the old syntax, using API version 0: