Here's a simple example of creating a business directory REST API in Python using Flask and SQLAlchemy:
main.py1890 chars53 linesIn this code, we define a Business class as a SQLAlchemy model, with id, name, and address attributes. We then define five Flask routes for interacting with the API: get_businesses for getting a list of all businesses, get_business for getting a single business by ID, create_business for creating a new business, update_business for updating an existing business by ID, and delete_business for deleting a business by ID.
To run this API, simply save the code to a file (e.g., app.py) and run it using the command python app.py. The API will listen on port 5000 by default, and you can interact with it using any REST client, such as Postman or cURL.
gistlibby LogSnag