This repository provides a simple tutorial on building a Flask API with CORS (Cross-Origin Resource Sharing) enabled. The tutorial explains the concepts of CORS and demonstrates how to implement CORS in a Flask API. The API serves as a foundation for developing web applications that require cross-origin requests.
You can find a detailed step-by-step tutorial about this repository on our blog: Flask API with CORS Tutorial
- Sets up a basic Flask API with routes for handling requests.
- Implements CORS to allow cross-origin requests from specific origins.
- Provides an example route for retrieving data.
- Clone the repository:
git clone https://github.com/riad-azz/flask-api-cors-tutorial.git
- Navigate to the project directory:
cd flask-api-cors-tutorial
- Create a virtual environment:
python -m venv myenv
- Activate the virtual environment:
For Mac/Linux:
source myenv/bin/activate
For Windows:
myenv\Scripts\activate
- Install the required dependencies:
pip install -r requirements.txt
- Start the Flask API:
python app.py
- Access the API using a web browser or a tool like cURL or Postman:
curl http://localhost:5000/api/data
This endpoint returns a JSON response containing a list of random people as dummy data.
This project is licensed under the MIT License.