bottle_rest submodule¶
-
bottle_rest.bottle_rest.
decode_json_body
()¶ Decode
bottle.request.body
to JSON.Returns: Structure decoded by json.loads()
.Return type: obj Raises: HTTPError
– 400 in case the data was malformed.
-
bottle_rest.bottle_rest.
encode_json_body
(data)¶ Return prettified JSON data, set
response.content_type
toapplication/json; charset=utf-8
.Parameters: data (any) – Any basic python data structure. Returns: Data converted to prettified JSON. Return type: str
-
bottle_rest.bottle_rest.
form_to_params
(fn=None, return_json=True)¶ Convert bottle forms request to parameters for the wrapped function.
Parameters: return_json (bool, default True) – Should the decorator automatically convert returned value to JSON?
-
bottle_rest.bottle_rest.
handle_type_error
(fn)¶ Convert
TypeError
tobottle.HTTPError
with400
code and message about wrong parameters.Raises: HTTPError
– 400 in case too many/too little function parameters were given.
-
bottle_rest.bottle_rest.
json_to_data
(fn=None, return_json=True)¶ Decode JSON from the request and add it as
data
parameter for wrapped function.Parameters: return_json (bool, default True) – Should the decorator automatically convert returned value to JSON?
-
bottle_rest.bottle_rest.
json_to_params
(fn=None, return_json=True)¶ Convert JSON in the body of the request to the parameters for the wrapped function.
If the JSON is list, add it to
*args
.If dict, add it to
**kwargs
in non-rewrite mode (no key in**kwargs
will be overwritten).If single value, add it to
*args
.Parameters: return_json (bool, default True) – Should the decorator automatically convert returned value to JSON?
-
bottle_rest.bottle_rest.
pretty_dump
(fn)¶ Decorator used to output prettified JSON.
response.content_type
is set toapplication/json; charset=utf-8
.Parameters: fn (fn pointer) – Function returning any basic python data structure. Returns: Data converted to prettified JSON. Return type: str