Changelog

Utilities

BustAPI provides several helper functions to make common web tasks easier.

jsonify(data)

Creates a Response with the given data serialized to JSON and the Content-Type header set to application/json.

return jsonify({"status": "ok"})

abort(status_code, description=None)

Raises an HTTP exception, stopping request processing immediately.

  • status_code (int): The HTTP status code (e.g., 404, 403).
  • description (str): Optional text description to show to the user.

redirect(location, code=302)

Returns a response redirecting the client to a new location.

  • location (str): The URL to redirect to.
  • code (int): The status code (301, 302, 303, 307, etc). Default is 302.

render_template(template_name, **context)

Renders a template from the templates folder with the given context.

  • template_name (str): The name of the template file (e.g., 'index.html').
  • **context: Keyword arguments representing variables available in the template.