Flask endpoint decorator.
Example:
@app.route('/cors-endpoint', methods=['GET', 'OPTIONS'])
@cors()
def cors_endpoint():
return jsonify(message='This is accessible via a cross-origin XHR')
# Or if you want to control the domains this resource can be requested
# from via CORS:
domains = ['http://wandborg.se', 'http://sfconservancy.org']
def restrict_domains(origin):
return ' '.join(domains)
@app.route('/restricted-cors-endpoint')
@cors(restrict_domains)
def restricted_cors_endpoint():
return jsonify(
message='This is accessible from %s' % ', '.join(domains))
Parameters: | origin_callback (function) – A callback that takes one str() argument containing the Origin HTTP header from the request object. This can be used to filter out which domains the resource can be requested via CORS from. |
---|
Bases: builtins.object
Bases: flask.json.JSONDecoder
Bases: flask.json.JSONEncoder
This module contains the high-level webservice logic such as the Flask setup and the Flask endpoints.
flask.Flask.before_request()-decorated method that initializes an accounting.Ledger object.
Returns the JSON-serialized output of accounting.Ledger.reg()
REST/JSON endpoint for transactions.
Current state:
Takes a POST request with a transactions JSON payload and writes it to the ledger file.
Requires the transactions payload to be __type__-annotated:
{
"transactions": [
{
"__type__": "Transaction",
"date": "2013-01-01",
"payee": "Kindly T. Donor",
"postings": [
{
"__type__": "Posting",
"account": "Income:Foo:Donation",
"amount": {
"__type__": "Amount",
"amount": "-100",
"symbol": "$"
}
},
{
"__type__": "Posting",
"account": "Assets:Checking",
"amount": {
"__type__": "Amount",
"amount": "100",
"symbol": "$"
}
}
]
}
}
becomes:
2013-01-01 Kindly T. Donor
Income:Foo:Donation $ -100
Assets:Checking $ 100