aggrex

command module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2018 License: MIT Imports: 13 Imported by: 0

README

AggreX

Just a scriptable APIs aggregator using the simple javascript syntax

curl -d "\
var continent = request({url: 'http://country.io/continent.json'}); \
var names = request({url: 'http://country.io/names.json'}); \
var exports = {
	c: continent.body,
	n: names.body
};\
" localhost:6030

Features

  • Using a simple javascript interpreter to execute your requests
  • Using the underscore.js library for helper functions
  • Lightweight & High concurrent request dispatcher
  • Built using Golang

Why

I wanted a genaric way to call multiple endpoints from the browser without the ajax hell so I won't reduce the page load performance, as well as I don't want to create a customized script to aggregate the endpoints for me, I need it to be genaric.

Installation

Just goto the releases page and download yours

Usage

CLI Flags
➜  ~ aggrex -h
Usage of aggrex:
  -allowed-hosts all are allowed
    	the allowed hosts, empty means all are allowed
  -http string
    	the http listen address (default ":6030")
  -max-body-size int
    	max body size in MB (default 2)
  -max-exec-time int
    	max execution time of each script in seconds (default 5)

Run
➜  ~ aggrex
Example
➜  ~ curl -d "exports.example = request({url: 'http://country.io/names.json'})" localhost:6030

Javascript API

as well as the basic javascript keywords/objects there are two things request() and _ (underscore)

# request(options)
var resp = request({
    url: "http://localhost",    // the url
    method: "GET",              // the http method
    headers: {                  // the request headers
        "key": "value"
    },
    body: ""                    // the request body (anything to be sent i.e 'string', 'object' ... etc)
})

var statusCode = resp.statusCode
var headers = resp.headers
var size = resp.size
var body = resp.body

// you must fill the exports variable, because this is the main var used as a response
exports.example = body

Contribution

Weclome :)

Author

I'm Mohammed Al Ashaal, a Gopher ;)

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL