This patch adds a RESTful HTTP interface to Asterisk.

The API itself is documented using Swagger, a lightweight mechanism for
documenting RESTful API's using JSON. This allows us to use swagger-ui
to provide executable documentation for the API, generate client
bindings in different languages, 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 templates.  The code generator is written in Python, and
uses Pystache. 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.

(closes issue ASTERISK-20891)
Review: https://reviewboard.asterisk.org/r/2376/

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@386232 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
David M. Lee
2013-04-22 14:58:53 +00:00
parent 1871017cc6
commit 1c21b8575b
63 changed files with 8605 additions and 59 deletions

View File

@@ -338,20 +338,15 @@ int ast_json_object_iter_set(struct ast_json *object, struct ast_json_iter *iter
/*!
* \brief Default flags for JSON encoding.
*/
static size_t dump_flags(void)
static size_t dump_flags(enum ast_json_encoding_format format)
{
/* There's a chance this could become a runtime flag */
int flags = JSON_COMPACT;
#ifdef AST_DEVMODE
/* In dev mode, write readable JSON */
flags = JSON_INDENT(2) | JSON_PRESERVE_ORDER;
#endif
return flags;
return format == AST_JSON_PRETTY ?
JSON_INDENT(2) | JSON_PRESERVE_ORDER : JSON_COMPACT;
}
char *ast_json_dump_string(struct ast_json *root)
char *ast_json_dump_string_format(struct ast_json *root, enum ast_json_encoding_format format)
{
return json_dumps((json_t *)root, dump_flags());
return json_dumps((json_t *)root, dump_flags(format));
}
static int write_to_ast_str(const char *buffer, size_t size, void *data)
@@ -385,25 +380,25 @@ static int write_to_ast_str(const char *buffer, size_t size, void *data)
return 0;
}
int ast_json_dump_str(struct ast_json *root, struct ast_str **dst)
int ast_json_dump_str_format(struct ast_json *root, struct ast_str **dst, enum ast_json_encoding_format format)
{
return json_dump_callback((json_t *)root, write_to_ast_str, dst, dump_flags());
return json_dump_callback((json_t *)root, write_to_ast_str, dst, dump_flags(format));
}
int ast_json_dump_file(struct ast_json *root, FILE *output)
int ast_json_dump_file_format(struct ast_json *root, FILE *output, enum ast_json_encoding_format format)
{
if (!root || !output) {
return -1;
}
return json_dumpf((json_t *)root, output, dump_flags());
return json_dumpf((json_t *)root, output, dump_flags(format));
}
int ast_json_dump_new_file(struct ast_json *root, const char *path)
int ast_json_dump_new_file_format(struct ast_json *root, const char *path, enum ast_json_encoding_format format)
{
if (!root || !path) {
return -1;
}
return json_dump_file((json_t *)root, path, dump_flags());
return json_dump_file((json_t *)root, path, dump_flags(format));
}
/*!