[asterisk-dev] [Code Review] 2376: Adding RESTful API's to Asterisk

David Lee reviewboard at asterisk.org
Fri Apr 19 13:06:15 CDT 2013


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviewboard.asterisk.org/r/2376/
-----------------------------------------------------------

(Updated April 19, 2013, 1:06 p.m.)


Review request for Asterisk Developers.


Changes
-------

Addressed review comments
 * Removed unnecessary whitespace change in utis.h
 * Fixed bad whitespace in resource_channels.c
 * Made doxygen comments in generated code more readable.

And some other changes
 * Added API's for sounds, recordings and playback
 * Made summaries consistently end with a period
 * Merged from trunk


Repository: Asterisk


Description
-------

This patch represents the first step toward adding a RESTful API to Asterisk.

The following is the file doc from res_stasis_http.c:

The API itself is documented using Swagger[1], a lightweight mechanism for
documenting RESTful API's using JSON. This allows us to use swagger-ui[2] to
provide executable documentation for the API, generate client bindings in
different languages[3], and generate a lot of the boilerplate code for
implementing the RESTful bindings. The API docs live in the rest-api/ directory.

The RESTful bindings are generated from the Swagger API docs using a
set of Mustache[4] templates.  The code generator is written in
Python, and uses Pystache[5]. Pystache has no dependencies, and be
installed easily using pip. Code generation code lives in
rest-api-templates/.

The generated code reduces a lot of boilerplate when it comes to handling
HTTP requests. It also helps us have greater consistency in the REST API.

The structure of the generated code is:

 - res/stasis_http/resource_{resource}.h
   - For each operation in the resouce, a generated argument structure
     (holding the parsed arguments from the request) and function
     declarations (to implement in res/stasis_http/resource_{resource}.c)
 - res_stasis_http_{resource}.c
   - A set of \ref stasis_rest_callback functions, which glue the two
     together. They parse out path variables and request parameters to
     populate a specific \c_args which is passed to the specific request
     handler (in res/stasis_http/resource_{resource}.c)
   - A tree of \ref stasis_rest_handlers for routing requests to its
     \ref stasis_rest_callback

The basic flow of an HTTP request is:

 - stasis_http_callback()
   1. Initial request validation
   2. Routes as either a doc request (stasis_http_get_docs) or API
      request (stasis_http_invoke)
      - stasis_http_invoke()
        1. Further request validation
        2. Routes the request through the tree of generated
           stasis_rest_handlers.
        3. Dispatch to the generated callback
           - stasis_http_*_cb
             1. Populate *_args struct with path and get params
             2. Invoke the request handler
   3. Validates and sends response

 [1]: https://developers.helloreverb.com/swagger/
 [2]: https://github.com/wordnik/swagger-ui
 [3]: https://github.com/asterisk/asterisk_rest_libraries
 [4]: http://mustache.github.io/mustache.5.html
 [5]: https://github.com/defunkt/pystache


Diffs (updated)
-----

  /trunk/Makefile 386104 
  /trunk/configs/stasis_http.conf.sample PRE-CREATION 
  /trunk/include/asterisk/http.h 386104 
  /trunk/include/asterisk/json.h 386104 
  /trunk/include/asterisk/stasis_app.h 386104 
  /trunk/include/asterisk/stasis_http.h PRE-CREATION 
  /trunk/include/asterisk/strings.h 386104 
  /trunk/main/http.c 386104 
  /trunk/main/json.c 386104 
  /trunk/res/Makefile 386104 
  /trunk/res/res_stasis.c 386104 
  /trunk/res/res_stasis_http.c PRE-CREATION 
  /trunk/res/res_stasis_http.exports.in PRE-CREATION 
  /trunk/res/res_stasis_http_asterisk.c PRE-CREATION 
  /trunk/res/res_stasis_http_bridges.c PRE-CREATION 
  /trunk/res/res_stasis_http_channels.c PRE-CREATION 
  /trunk/res/res_stasis_http_endpoints.c PRE-CREATION 
  /trunk/res/res_stasis_http_events.c PRE-CREATION 
  /trunk/res/res_stasis_http_playback.c PRE-CREATION 
  /trunk/res/res_stasis_http_recordings.c PRE-CREATION 
  /trunk/res/res_stasis_http_sounds.c PRE-CREATION 
  /trunk/res/stasis_http.make PRE-CREATION 
  /trunk/res/stasis_http/resource_asterisk.h PRE-CREATION 
  /trunk/res/stasis_http/resource_asterisk.c PRE-CREATION 
  /trunk/res/stasis_http/resource_bridges.h PRE-CREATION 
  /trunk/res/stasis_http/resource_bridges.c PRE-CREATION 
  /trunk/res/stasis_http/resource_channels.h PRE-CREATION 
  /trunk/res/stasis_http/resource_channels.c PRE-CREATION 
  /trunk/res/stasis_http/resource_endpoints.h PRE-CREATION 
  /trunk/res/stasis_http/resource_endpoints.c PRE-CREATION 
  /trunk/res/stasis_http/resource_events.h PRE-CREATION 
  /trunk/res/stasis_http/resource_events.c PRE-CREATION 
  /trunk/res/stasis_http/resource_playback.h PRE-CREATION 
  /trunk/res/stasis_http/resource_playback.c PRE-CREATION 
  /trunk/res/stasis_http/resource_recordings.h PRE-CREATION 
  /trunk/res/stasis_http/resource_recordings.c PRE-CREATION 
  /trunk/res/stasis_http/resource_sounds.h PRE-CREATION 
  /trunk/res/stasis_http/resource_sounds.c PRE-CREATION 
  /trunk/rest-api-templates/README.txt PRE-CREATION 
  /trunk/rest-api-templates/asterisk_processor.py PRE-CREATION 
  /trunk/rest-api-templates/do-not-edit.mustache PRE-CREATION 
  /trunk/rest-api-templates/make_stasis_http_stubs.py PRE-CREATION 
  /trunk/rest-api-templates/odict.py PRE-CREATION 
  /trunk/rest-api-templates/res_stasis_http_resource.c.mustache PRE-CREATION 
  /trunk/rest-api-templates/rest_handler.mustache PRE-CREATION 
  /trunk/rest-api-templates/stasis_http.make.mustache PRE-CREATION 
  /trunk/rest-api-templates/stasis_http_resource.c.mustache PRE-CREATION 
  /trunk/rest-api-templates/stasis_http_resource.h.mustache PRE-CREATION 
  /trunk/rest-api-templates/swagger_model.py PRE-CREATION 
  /trunk/rest-api-templates/transform.py PRE-CREATION 
  /trunk/rest-api/README.txt PRE-CREATION 
  /trunk/rest-api/api-docs/asterisk.json PRE-CREATION 
  /trunk/rest-api/api-docs/bridges.json PRE-CREATION 
  /trunk/rest-api/api-docs/channels.json PRE-CREATION 
  /trunk/rest-api/api-docs/endpoints.json PRE-CREATION 
  /trunk/rest-api/api-docs/events.json PRE-CREATION 
  /trunk/rest-api/api-docs/playback.json PRE-CREATION 
  /trunk/rest-api/api-docs/recordings.json PRE-CREATION 
  /trunk/rest-api/api-docs/sounds.json PRE-CREATION 
  /trunk/rest-api/resources.json PRE-CREATION 
  /trunk/tests/test_stasis.c 386104 
  /trunk/tests/test_stasis_http.c PRE-CREATION 
  /trunk/tests/test_strings.c 386104 

Diff: https://reviewboard.asterisk.org/r/2376/diff/


Testing
-------

Unit tests


Thanks,

David Lee

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20130419/8ae73be8/attachment.htm>


More information about the asterisk-dev mailing list