Giter Site home page Giter Site logo

fask_queueing_api's Introduction

#Test Api

Online API system using flask, flask-restful, sqlalchemy,

The project has been developed using Flask- A python Micro-web framework and other additional packages describe below in Tech Stack Section.

Installation

Before we begin, kindly install following on your system:-

How to Run the App?

  • virtualenv -p ‘which python3’ venv
  • source venv/bin/activate
  • Dump user.sql into Mysql (user.sql is a small section of CSV provided)
  • pip install -r requirements.txt
  • python3 worker.py (Separate instance)
  • python3 run.py

Everything should be ready. In your browser open http://127.0.0.1:5000/

Since Redis-Server is used for database optimisation (caching) After running the app, type in following in terminal to establish redis-connection

  • redis-server

REST Endpoints

There are two major objects in the app:-

  • Implementation of query mechanism in Rest APIs for analytics
  • APIs to upload file for custom analytics

The endpoints and the corresponding REST operations are defined as follows:-

Endpoints

- Method: `GET`
- URL path: `/api/users?platform=android`
- Response:

Header: `HTTP 200`
Body:
  ```
  {
    "data": {
    "percentage_share": 66.43,
    "platform_users": 5933,
    "unique_users": 5932
    }
  }
  ```
or

Header: `HTTP <HTTP_CODE>`
Body:
  ```json
  {
      "error": "ERROR_DESCRIPTION"
  }
  ```

Returns the task_id generated on uploading of file to the task queue

- Method: `POST`
- URL path: `/api/upload`
- Request body:

```
{
    Sample File for Upload
}
```
- Response:

Header: `HTTP 200`
Body:
  ```  
  {
      {"data":{"task_id":"e8d310de-dc05-4612-a897-002d0b1c7fe6"},"status":"success"}

  }
  ```
or

Header: `HTTP <HTTP_CODE>`
Body:
  ```json
  {
      "error": "ERROR_DESCRIPTION"
  }
  ```
- Method: `GET`
- URL path: `/api/upload/e8d310de-dc05-4612-a897-002d0b1c7fe6`
- Response:

Header: `HTTP 200`
Body:
  ```
{
    "data": {
        "task_id": "e8d310de-dc05-4612-a897-002d0b1c7fe6",
        "task_result": true,
        "task_status": "finished"
    },
    "status": "success"
}
  ```
or

Header: `HTTP <HTTP_CODE>`
Body:
  ```json
  {
      "error": "ERROR_DESCRIPTION"
  }
  ```

Tech stack

  • Flask - Web Microframework for Python
  • Flask-restful - Extension for flask for quickly building REST APIs
  • Flask-migrate - An extension that handles SQLAlchemy database migrations for Flask applications using Alembic.
  • Flask-sqlalchemy - This is an extension of flask that add supports for SQLAlchemy
  • MySQL - Database for the project. It comes built in with python.
  • RedisDB - Key-Value based No-SQL DB to oprimize relational database by improving Read by caching data and queing data.
  • Redis Queue - RQ is a simple Python library for queueing jobs and processing them in the background with workers.
  • Flask-Redis - An flask extension of RedisPy to easliy used Redis with Python and Flask easily.

Development Thought process

  • Used Micro service Architecture for proper decoupling of service.
  • Test driven development is useful and leads to less errors in later stages of development.
  • Dependency injection helps a lot in Test driven development and also in making the project more modular and flexible. Though couldn’t use in the current project but would surely update the project using flask-injector.
  • Used RedisDB and Redis Queue which supported the whole architecture either its caching purpose or queueing and pooling the app.
  • Used Flask because it’s flexible and can be plugged with all the necessary modules on the go.

fask_queueing_api's People

Contributors

bhardwajrahul avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.