I'm trying to use url paths in my google function and can't seem to access the body of the curl request, it returns None
.
This is my code:
from flask import Flask, request, jsonify
import werkzeug.datastructures
from google.cloud import pubsub_v1
import json
import functions_framework
app = Flask(__name__)
@app.route('/')
def root():
return 'Hello World!'
@app.route('/v1/dummy/<dummy_id>/notdummy/<notdummy_id>/validate', methods=['POST'])
def validate(dummy_id, notdummy_id):
return {"function":"provision",
"dummy_id":dummy_id,
"notdummy_id":notdummy_id,
"body":content_data}
def main(request):
with app.app_context():
global content_data
content_data = request.get_json(silent=True)
headers = werkzeug.datastructures.Headers()
for key, value in request.headers.items():
headers.add(key, value)
with app.test_request_context(method=request.method, base_url=request.base_url, path=request.path, query_string=request.query_string, headers=headers, data=request.form):
try:
rv = app.preprocess_request()
if rv is None:
rv = app.dispatch_request()
except Exception as e:
rv = app.handle_user_exception(e)
response = app.make_response(rv)
return app.process_response(response)
And my curl request to call the google function.
curl -X POST https://region-environment.cloudfunctions.net/function-name/v1/dummy/id1/notdummy/id2/validate -d {"key":"value"}