Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

counter_api.py 900 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  1. import flask
  2. app = flask.Flask(__name__)
  3. counter = 3
  4. @app.route("/add_one", methods=["POST"])
  5. def add_one():
  6. global counter
  7. counter += 1
  8. return flask.jsonify({})
  9. @app.route("/get_count", methods=["GET"])
  10. def get_count():
  11. return flask.jsonify({"counter": counter})
  12. # If you want to assert on the final state the app must include this method
  13. @app.route("/get_state", methods=["GET"])
  14. def get_state():
  15. return flask.jsonify({"counter": counter})
  16. # If you want the app to be cleaned up it must include this method
  17. @app.route("/shutdown", methods=["POST"])
  18. def shutdown():
  19. func = flask.request.environ.get("werkzeug.server.shutdown")
  20. if func is None:
  21. return flask.jsonify({"message": "Error: not running with the Werkzeug Server"})
  22. func()
  23. return flask.jsonify({"message": "Server shutting down..."})
  24. if __name__ == "__main__":
  25. app.run(port=8765)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...