Giter Site home page Giter Site logo

flask-aggregator's Introduction

Flask-Aggregator

image

Batch the GET requests to your API into a single POST. Save requests latency and reduce REST chatiness.

I was inspired by this article from 3scale, and by their NGINX aggregator - but I wanted something simpler.

What does it do?

Flask-Aggregator adds an endpoint to your Flask application that handles multiple GET requests in a single POST, and returns the response of each GET request in a JSON stream.

What does that mean?

It means that instead of sending multiple GET requests:

-> GET /route1
<- answer1
-> GET /route2
<- answer2
-> GET /route3
<- answer3

You can now just send a single POST that aggregates them all:

-> POST /aggregate ["/route1", "/route2", "/route3"]
<- {
       "/route1": answer1,
<-     "/route2": answer2,
<-     "/route3": answer3
   }

Why?

Mobile networks.

How to install?

$ pip install flask-aggregator

How to setup my application?

from flask import Flask
from flask_aggregator import Aggregator

app = Flask(__name__)
Aggregator(app=app, endpoint="/batch")

How to aggregate?

$ python example.py
[go to another shell]
$ curl -H "Content-type: application/json" -X POST 127.0.0.1:5000/batch \
             --data-raw '["/hello/world", "/hello/ramnes?question=Sup?"]'
{
    "/hello/world": "Hello, world!",
    "/hello/ramnes?question=Sup?": "Hello, ramnes! Sup?"
}

Is it ready for production yet?

Not really.

As of today, Flask-Aggregator executes the aggregated requests in a synchronous manner, which makes it only useful if latency is a real issue and response time is not, and that more than N requests are sent at the same time, where N is maximum number of concurrent requests on user's client.

Also, it has limitations such has:

  • no automatic caching mechanism browser-side, since it uses a POST request
  • no header support at all for now, which means no cookie, etag, or whatever
  • no other HTTP verb than GET is supported for now

Last but not least, chances are high that a lot of corner cases are not handled.

License

MIT

flask-aggregator's People

Contributors

ramnes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

webclinic017

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.