diff options
author | David M. Lee <dlee@digium.com> | 2013-04-22 14:58:53 +0000 |
---|---|---|
committer | David M. Lee <dlee@digium.com> | 2013-04-22 14:58:53 +0000 |
commit | 1c21b8575bfd70b98b1102fd3dd09fc0bc335e14 (patch) | |
tree | 9a6ef6074e545ad2768bc1994e1a233fc1443729 /main | |
parent | 1871017cc6bd2e2ce7c638eeb6813e982377a521 (diff) |
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
Diffstat (limited to 'main')
-rw-r--r-- | main/http.c | 6 | ||||
-rw-r--r-- | main/json.c | 27 |
2 files changed, 17 insertions, 16 deletions
diff --git a/main/http.c b/main/http.c index aff38c3aa..ec9517f2c 100644 --- a/main/http.c +++ b/main/http.c @@ -153,6 +153,8 @@ static const struct ast_cfhttp_methods_text { { AST_HTTP_POST, "POST" }, { AST_HTTP_HEAD, "HEAD" }, { AST_HTTP_PUT, "PUT" }, + { AST_HTTP_DELETE, "DELETE" }, + { AST_HTTP_OPTIONS, "OPTIONS" }, }; const char *ast_get_http_method(enum ast_http_method method) @@ -897,6 +899,10 @@ static void *httpd_helper_thread(void *data) http_method = AST_HTTP_HEAD; } else if (!strcasecmp(method,"PUT")) { http_method = AST_HTTP_PUT; + } else if (!strcasecmp(method,"DELETE")) { + http_method = AST_HTTP_DELETE; + } else if (!strcasecmp(method,"OPTIONS")) { + http_method = AST_HTTP_OPTIONS; } uri = ast_skip_blanks(uri); /* Skip white space */ diff --git a/main/json.c b/main/json.c index 2aa53875b..1ff563871 100644 --- a/main/json.c +++ b/main/json.c @@ -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)); } /*! |