Skip to main content

Batch the GET requests to your REST API into a single POST

Project description

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 reponse of each GET request in a single JSON answer.

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?

Well, read the source code and decide by yourself!

Chances are high that a lot of corner cases are not handled.

License

MIT

Project details


Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page