https://github.com/riad-azz/flask-api-cors-tutorial
A step-by-step tutorial on building a Flask API with CORS (Cross-Origin Resource Sharing) enabled. Learn how to implement CORS in a Flask API to handle cross-origin requests and develop web applications with secure and controlled cross-origin access.
https://github.com/riad-azz/flask-api-cors-tutorial
api cors flask flask-api flask-cors python tutorial web-development
Last synced: about 1 year ago
JSON representation
A step-by-step tutorial on building a Flask API with CORS (Cross-Origin Resource Sharing) enabled. Learn how to implement CORS in a Flask API to handle cross-origin requests and develop web applications with secure and controlled cross-origin access.
- Host: GitHub
- URL: https://github.com/riad-azz/flask-api-cors-tutorial
- Owner: riad-azz
- Created: 2023-06-25T14:24:59.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-25T14:26:31.000Z (almost 3 years ago)
- Last Synced: 2024-12-30T10:52:07.989Z (over 1 year ago)
- Topics: api, cors, flask, flask-api, flask-cors, python, tutorial, web-development
- Language: Python
- Homepage: https://utopia-insights.dev/building-a-simple-flask-api-with-cors-a-comprehensive-tutorial-for-cross-origin-resource-sharing
- Size: 1000 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Flask API with CORS Tutorial
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](https://utopia-insights.dev/building-a-simple-flask-api-with-cors-a-comprehensive-tutorial-for-cross-origin-resource-sharing)
## Features
- 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.
## Installation
1. Clone the repository:
```bash
git clone https://github.com/riad-azz/flask-api-cors-tutorial.git
```
2. Navigate to the project directory:
```bash
cd flask-api-cors-tutorial
```
3. Create a virtual environment:
```bash
python -m venv myenv
```
4. Activate the virtual environment:
For Mac/Linux:
```bash
source myenv/bin/activate
```
For Windows:
```bash
myenv\Scripts\activate
```
5. Install the required dependencies:
```bash
pip install -r requirements.txt
```
## Usage
1. Start the Flask API:
```bash
python app.py
```
2. Access the API using a web browser or a tool like cURL or Postman:
```bash
curl http://localhost:5000/api/data
```
This endpoint returns a JSON response containing a list of random people as dummy data.
## License
This project is licensed under the [MIT License](LICENSE).