示例#1
0
def make_response(data):
    """
    Creates a 200-status JSON response with the provided data
    and returns it to the caller
    :data the data to include in the response
    """

    response = { "meta": { 'status': 200 }, "data": data }

    response = respond((json.dumps(response), 200))
    response.headers['Content-Type'] = 'application/json'
    return response
示例#2
0
def make_error(errors):
    """
    Creates a JSON response with the provided errors. The status
    is determined by the highest code in the provided list of errors.
    The response object is returned to the caller
    :errors a single error or list of errors
    """

    error_list = []
    if type(errors) is not list:
        errors = [errors]
    for error in errors:
        error_list.append(error.to_dict())

    status = max(error.status for error in errors)
    response = { "meta": { 'status': status }, "errors": error_list }
    response = respond((json.dumps(response), status))
    response.headers['Content-Type'] = 'application/json'
    return response
示例#3
0
def created(data):
    return respond(data, 201)
示例#4
0
def ok(data):
    return respond(data, 200)
示例#5
0
def not_allowed(method):
    return respond({'method': method}, 405)
示例#6
0
def no_content():
    return respond('', 204)