Junior — Middle
What tool or approach would you use to develop an API method (endpoint)?
sobes.tech AI
Answer from AI
Python frameworks such as Flask or FastAPI are often used for developing API methods. They allow for quick creation of endpoints with minimal code.
Example of a simple API method with Flask:
from flask import Flask, jsonify, request
app = Flask(__name__)
@app.route('/api/items', methods=['GET'])
def get_items():
items = [{'id': 1, 'name': 'Item 1'}, {'id': 2, 'name': 'Item 2'}]
return jsonify(items)
if __name__ == '__main__':
app.run(debug=True)
FastAPI additionally supports automatic documentation generation and data validation, which is convenient for more complex APIs.
The choice of tool depends on the project requirements, but Flask and FastAPI are excellent options for quick startup.