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

David Lee reviewboard at asterisk.org
Thu Mar 14 14:04:03 CDT 2013



> On March 14, 2013, 1:44 p.m., Matt Jordan wrote:
> > Not much yet; still looking through it.
> > 
> > As a general question - do we have an 'automatic' way of getting swagger and generating the documentation?

There are some options.

swagger-ui[1] generates nice live documentation, but has settings in the HTML that need to be tweaked for Asterisk (which I've done in my fork[2]). It also needs a live system to point to, which is not great for generating docs for a static site. But it's useful for playing around with the API on their local system.

I discovered yesterday that swagger-codegen[3] has templates for generating static HTML docs. I haven't looked at it yet, but that's probably our best bet for generating docs, like we do for doxygen.asterisk.org.

 [1]: https://github.com/wordnik/swagger-ui
 [2]: https://github.com/leedm777/swagger-ui
 [3]: https://github.com/wordnik/swagger-codegen


> On March 14, 2013, 1:44 p.m., Matt Jordan wrote:
> > /team/dlee/stasis-app/Makefile, lines 953-954
> > <https://reviewboard.asterisk.org/r/2376/diff/1/?file=34029#file34029line953>
> >
> >     Just for the sake of being nice to people, there's a dependency check for Python available:
> >     
> >     ifeq ($(PYTHON),:)
> >         @echo Complain
> >     fi
> >     
> >

Fixed.


> On March 14, 2013, 1:44 p.m., Matt Jordan wrote:
> > /team/dlee/stasis-app/cog/res_stasis_http.make.cog, line 8
> > <https://reviewboard.asterisk.org/r/2376/diff/1/?file=34031#file34031line8>
> >
> >     Blob

Fixed.


> On March 14, 2013, 1:44 p.m., Matt Jordan wrote:
> > /team/dlee/stasis-app/cog/stasis_cog.py, lines 276-277
> > <https://reviewboard.asterisk.org/r/2376/diff/1/?file=34032#file34032line276>
> >
> >     You're not going to enjoy this, but... we've tried not to use OrderedDict as it was new in Python 2.7.  CentOS 6 is shipping with Python 2.6.x... so, it would be better if we didn't rely on it.

That can't be right; 2.7 is over 2.5 years old. Surely EL6 has it.

*checks*... *sighs*

I'll deal with it.


- David


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


On March 7, 2013, 11:03 a.m., David Lee wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviewboard.asterisk.org/r/2376/
> -----------------------------------------------------------
> 
> (Updated March 7, 2013, 11:03 a.m.)
> 
> 
> Review request for Asterisk Developers.
> 
> 
> Summary
> -------
> 
> 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
> Cog.py[4] templates. Cog.py is extemely lightweight (maybe too lightweight), and
> can be installed easily using pip. Template scripts live in the cog/ directory,
> and the generated code lives in the res/stasis-http/ directory.
> 
> The structure of the generated code is:
> 
>  - A tree of stasis_rest_handlers which are used for request routing.
>  - Prototypes for request handlers, and structures for passing arguments in
>    the request handler.
>  - A set of stasis_rest_callback functions, which glue the two
>    together. They parse out path variables and request parameters to populate
>    a specific *_args which is passed to the specific request handler.
> 
> The use of the generated *_args allows for greater type safety and reduced
> boilerplate in the request handlers themselves.
> 
> 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://nedbatchelder.com/code/cog/
> 
> 
> Diffs
> -----
> 
>   /team/dlee/stasis-app/Makefile 382603 
>   /team/dlee/stasis-app/build_tools/make_stasis_http_stubs PRE-CREATION 
>   /team/dlee/stasis-app/cog/res_stasis_http.make.cog PRE-CREATION 
>   /team/dlee/stasis-app/cog/stasis_cog.py PRE-CREATION 
>   /team/dlee/stasis-app/cog/stasis_http_resource.c.cog PRE-CREATION 
>   /team/dlee/stasis-app/cog/stasis_http_resource.h.cog PRE-CREATION 
>   /team/dlee/stasis-app/cog/stasis_http_resources.c.cog PRE-CREATION 
>   /team/dlee/stasis-app/include/asterisk/http.h 382603 
>   /team/dlee/stasis-app/include/asterisk/stasis_http.h PRE-CREATION 
>   /team/dlee/stasis-app/include/asterisk/strings.h 382603 
>   /team/dlee/stasis-app/include/asterisk/utils.h 382603 
>   /team/dlee/stasis-app/main/http.c 382603 
>   /team/dlee/stasis-app/res/Makefile 382603 
>   /team/dlee/stasis-app/res/res_stasis_http.c PRE-CREATION 
>   /team/dlee/stasis-app/res/res_stasis_http.exports.in PRE-CREATION 
>   /team/dlee/stasis-app/res/res_stasis_http.make PRE-CREATION 
>   /team/dlee/stasis-app/res/stasis_http/resource_asterisk.h PRE-CREATION 
>   /team/dlee/stasis-app/res/stasis_http/resource_asterisk.c PRE-CREATION 
>   /team/dlee/stasis-app/res/stasis_http/resource_bridges.h PRE-CREATION 
>   /team/dlee/stasis-app/res/stasis_http/resource_bridges.c PRE-CREATION 
>   /team/dlee/stasis-app/res/stasis_http/resource_channels.h PRE-CREATION 
>   /team/dlee/stasis-app/res/stasis_http/resource_channels.c PRE-CREATION 
>   /team/dlee/stasis-app/res/stasis_http/resource_endpoints.h PRE-CREATION 
>   /team/dlee/stasis-app/res/stasis_http/resource_endpoints.c PRE-CREATION 
>   /team/dlee/stasis-app/res/stasis_http/resource_recordings.h PRE-CREATION 
>   /team/dlee/stasis-app/res/stasis_http/resource_recordings.c PRE-CREATION 
>   /team/dlee/stasis-app/res/stasis_http/resources.c PRE-CREATION 
>   /team/dlee/stasis-app/rest-api/README.txt PRE-CREATION 
>   /team/dlee/stasis-app/rest-api/asterisk.json PRE-CREATION 
>   /team/dlee/stasis-app/rest-api/bridges.json PRE-CREATION 
>   /team/dlee/stasis-app/rest-api/channels.json PRE-CREATION 
>   /team/dlee/stasis-app/rest-api/endpoints.json PRE-CREATION 
>   /team/dlee/stasis-app/rest-api/recordings.json PRE-CREATION 
>   /team/dlee/stasis-app/rest-api/resources.json PRE-CREATION 
>   /team/dlee/stasis-app/tests/test_stasis_http.c PRE-CREATION 
>   /team/dlee/stasis-app/tests/test_strings.c 382603 
> 
> Diff: https://reviewboard.asterisk.org/r/2376/diff
> 
> 
> Testing
> -------
> 
> Unit tests
> 
> 
> Thanks,
> 
> David
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20130314/475ed29a/attachment-0001.htm>


More information about the asterisk-dev mailing list