ARI REST Requests over Websocket

Historically, using ARI required using HTTP for making REST requests and getting their responses, and a Websocket for receiving events.  With Asterisk 20.14.0, 21.9.0 and 22.4.0 however, you can simplify your client applications by submitting ARI REST requests over the same websocket you currently use to receive events.

There are several published protocols for request/response type communication over Websockets including WAMP, JSON-RPC, XMPP, Socket.IO, etc. but these are all fairly heavyweight and would require significant effort to implement in Asterisk. Instead we went with a simple JSON wrapper inspired by SwaggerSocket.

Here’s a simple request/response example that answers a channel:

Request:

{
    "type": "RESTRequest",
    "transaction_id": "d1eb679c-166f-4278-8b28-0340088a3410",
    "request_id": "1e409d15-a35e-4946-b270-c460cc45b2c4",
    "method": "POST",
    "uri": "channels/ast-1741988825.0/answer"
}

Response:

{
    "type": "RESTResponse",
    "transaction_id": "d1eb679c-166f-4278-8b28-0340088a3410",
    "request_id": "1e409d15-a35e-4946-b270-c460cc45b2c4",
    "status_code": 204,
    "reason_phrase": "No Content",
    "uri": "channels/ast-1741988825.0/answer"
    "timestamp": "2025-03-17T08:32:35.709-0600",
    "asterisk_id": "e4:1d:2d:b8:3b:a0",
    "application": "mystasisapp"
}

Pretty simple!  The transaction_id and request_id are properties you can provide on your requests and will be echoed back in the response for that request.  You can use them to correlate the two and to correlate multiple requests together.  The rest of the properties should all be familiar.  In fact, the response is a standard ARI Event.

For more detailed information, visit the “ARI REST over Websocket” page on the Asterisk Documentation web site.

 

 

 

About the Author

What can we help you find?