Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/app-generator/sample-flask-api-restx

Flask API Sample - Open-Source API Server | AppSeed
https://github.com/app-generator/sample-flask-api-restx

appseed-sample flask-restx flask-sample

Last synced: 2 months ago
JSON representation

Flask API Sample - Open-Source API Server | AppSeed

Awesome Lists containing this project

README

        

# Flask API Sample

Simple [Flask API Server](https://blog.appseed.us/simple-flask-api-server/) powered by Flask-RestX, SqlAlchemy, **SQLite** persistence - Provided by **AppSeed**.


> Features:

- `Up-to-date dependencies`
- Simple, intuitive codebase - can be extended with ease.
- `Flask-restX`
- `Docker` support
- Free [support](https://appseed.us/support) via email and [Discord](https://discord.gg/fZC6hup) (1k+ community).


## ✨ API Definition

| Route | Verb | Info | Status |
| --- | --- | --- | --- |
| `/datas` | **GET** | return all items | ✔️ |
| | **POST** | create a new item | ✔️ |
| `/datas:id` | **GET** | return one item | ✔️ |
| | **PUT** | update item | ✔️ |
| | **DELETE** | delete item | ✔️ |


## ✨ Quick Start in `Docker`

> Get the code

```bash
$ git clone https://github.com/app-generator/flask-api-sample.git
$ cd flask-api-sample
```

> Start the app in Docker

```bash
$ docker-compose up --build
```

The API server will start using the PORT `5000`.


![Flask API Server - Open-source Flask Starter provided by AppSeed.](https://user-images.githubusercontent.com/51070104/126349643-264d4cf4-6d0b-4c24-8185-adf69409fa4e.png)


## ✨ How to use the code

> **Step #1** - Clone the project

```bash
$ git clone https://github.com/app-generator/flask-api-sample.git
$ cd flask-api-sample
```


> **Step #2** - create virtual environment using python3 and activate it (keep it outside our project directory)

```bash
$ # Virtualenv modules installation (Unix based systems)
$ virtualenv env
$ source env/bin/activate
$
$ # Virtualenv modules installation (Windows based systems)
$ # virtualenv env
$ # .\env\Scripts\activate
```


> **Step #3** - Install dependencies in virtualenv

```bash
$ pip install -r requirements.txt
```


> **Step #4** - setup `flask` command for our app

```bash
$ export FLASK_APP=run.py
$ export FLASK_ENV=development
```

> Or for Windows-based systems

```powershell
$ (Windows CMD) set FLASK_APP=run.py
$ (Windows CMD) set FLASK_ENV=development
$
$ (Powershell) $env:FLASK_APP = ".\run.py"
$ (Powershell) $env:FLASK_ENV = "development"
```


> **Step #5** - start test APIs server at `localhost:5000`

```bash
$ flask run
```

Use the API via `POSTMAN` or Swagger Dashboard.

![Flask API Sample - Swagger Dashboard.](https://user-images.githubusercontent.com/51070104/151857217-ec364df4-cc90-413f-8bbe-a65e45dc8c35.png)


## ✨ Project Structure

```bash
api-server-flask/
├── api
│   ├── __init__.py
│   ├── config.py
│   ├── models.py
│   └── routes.py
├── README.md
├── requirements.txt
└── run.py
```

---
**[Flask API Sample](https://appseed.us/boilerplate-code/flask-api-boilerplate)** - provided by AppSeed [App Generator](https://appseed.us)