Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

flask echo server

from pprint import pprint
from textwrap import wrap
from flask import Flask, jsonify, request

app = Flask(__name__)
methods = ["GET", "POST", "PATCH", "DELETE"]


@app.route("/", methods=methods, defaults={"path": ""})
@app.route("/<path:path>", methods=methods)
def hello_world(path):
    divider = "================================================================"
    j = request.get_json()

    print(divider)
    print(f"*** Received data at: {path}")

    print("
** data:")
    print("
".join(wrap(request.data.decode())))

    print("
** form:")
    pprint(request.form)

    print("
** json:")
    pprint(j)

    print(f"{divider}

")

    return jsonify(
        {
            "endpoint": path,
            "data": request.data.decode("utf-8"),
            "form": request.form,
            "json": request.get_json(),
        }
    )


if __name__ == "__main__":
    app.run()
Comment

PREVIOUS NEXT
Code Example
Python :: web3.py failing not installing 
Python :: jsonpath in python verwenden 
Python :: telegram bot carousel 
Python :: django.core.exceptions.ImproperlyConfigured: Field name is not valid for model 
Python :: unzipping the value using zip() python 
Python :: if lower: --- 71 doc = doc.lower() 72 if accent_function is not None: 73 doc = accent_function(doc) 
Python :: Python OPERATORS, Data Types: LIST, SET, TUPLE, DICTIONARY 
Python :: quadrilateral 
Python :: list generation for python 
Python :: metodo de clase python 
Python :: how to write a first program in machine learning 
Python :: how to plot quantity of each value of a feature in python 
Python :: select columns rsnge dataframe 
Python :: Forth step - Creating new app 
Python :: summation 
Python :: pandascheck if two columns match and populate new column 
Python :: #adding for loop with tuple and having space 
Python :: folium add a polygon to a map 
Python :: find number of x greater than threshold in list python 
Python :: ploting bargraph with value_counts(with title x and y label and name angle) 
Python :: &quot;DO_NOTHING&quot; is not defined django 
Python :: RuntimeError: DataLoader worker (pid(s) 13615) exited unexpectedly 
Python :: Encapsulation in Python using public members 
Python :: splitting x,y using iloc 
Python :: connect two mathod to the same button in pyq5 
Python :: how to save multiple choices in django site:stackoverflow.com 
Python :: arma-garch python 
Python :: gdal user with anaconda 
Python :: what is mysoace 
Python :: frogenset ito dataframe pandas 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =