pip install httpz python from httpz import api, app @api.endpoint('/users', methods=['GET']) def get_all_users(): return {'users': ['User1', 'User2', 'User3']} @api.endpoint('/users/<int:user_id>', methods=['GET']) def get_user(user_id): return {'user_id': user_id, 'name': 'User' + str(user_id)} @api.endpoint('/users', methods=['POST']) def create_user(): user = app.request.json return {'message': 'User created successfully', 'user': user} python from httpz import api if __name__ == '__main__': api.run(host='0.0.0.0', port=5000, debug=True) bash curl http://localhost:5000/users bash curl http://localhost:5000/users/1 bash curl -X POST -H "Content-Type: application/json" -d '{"name":"new_user"}' http://localhost:5000/users


上一篇:
下一篇:
切换中文