現在の request だけでなく、 RESTful API エンドポイントごとに関連リンクを生成しようとしています。受け入れられるもう 1 つの方法は、現在のブループリント (この場合は「blueprint_name」と呼ばれる) のすべてのエンドポイントを生成することです。これが私の現在のセットアップの要約です:
def function_that_generates_links():
#what should I put here?
blueprint_name = Blueprint('blueprint_name', __name__, url_prefix='/blueprint_name')
@blueprint_name.route('/', methods=['GET'])
def endpoint_name():
#regular_data_being_sent_out is defined somewhere here
return jsonify(data=regular_data_being_sent_out,
links=function_that_generates_links())
@blueprint_name.route('/other_place', methods=['POST'])
def endpoint_name_other():
#regular_data_being_sent_out is defined somewhere here
return jsonify(data=regular_data_being_sent_out,
links=function_that_generates_links())
@blueprint_name.route('/another_place', methods=['DELETE'])
def endpoint_name_another_place():
#regular_data_being_sent_out is defined somewhere here
return jsonify(data=regular_data_being_sent_out,
links=function_that_generates_links())
@blueprint_name.route('/yet_another_place', methods=['PUT'])
def endpoint_name_yet_another_place():
#regular_data_being_sent_out is defined somewhere here
return jsonify(data=regular_data_being_sent_out,
links=function_that_generates_links())
各エンドポイントによって発行された各応答に、他のすべてのエンドポイントの適切な http '署名' を追加したいと考えています。上記のコード例では、「function_that_generates_links()」がこれを行う関数になります。url_encode() が使用できる必要なリンクを提供することは既にわかっていますが、適切な http 動詞(GET、POST、DELETE など) も必要です。私が立ち往生している対応するhttp-動詞/メソッドを見つけています。動詞がないとリンクが不完全/役に立たないため、動詞は重要です。