Skip to content

Instantly share code, notes, and snippets.

@monperrus
Created March 16, 2025 10:30
Show Gist options
  • Select an option

  • Save monperrus/50bac0eb0174c6b2352617587932ae14 to your computer and use it in GitHub Desktop.

Select an option

Save monperrus/50bac0eb0174c6b2352617587932ae14 to your computer and use it in GitHub Desktop.
a simple python application which expose an example service hello
from flask import Flask, request, jsonify
from datetime import datetime
app = Flask(__name__)
@app.route('/')
def root():
return jsonify({
'message': 'Welcome to the Hello Service',
'endpoints': {
'/hello': 'Get a hello message',
'/hello/<name>': 'Get a personalized hello message',
'/hello/time': 'Get hello message with current time'
}
})
@app.route('/hello')
def hello():
return jsonify({
'message': 'Hello, World!',
'timestamp': datetime.now().isoformat()
})
@app.route('/hello/<name>')
def hello_name(name):
return jsonify({
'message': f'Hello, {name}!',
'timestamp': datetime.now().isoformat()
})
@app.route('/hello/time')
def hello_time():
return jsonify({
'message': 'Hello!',
'time': datetime.now().strftime('%H:%M:%S'),
'date': datetime.now().strftime('%Y-%m-%d')
})
@app.errorhandler(404)
def not_found(error):
return jsonify({
'error': 'Not found',
'message': 'The requested endpoint does not exist'
}), 404
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment