Coder Social home page Coder Social logo

glue's Introduction

Glue

Lightweight language to easily handle communication between REST APIs

Goals

  • Easy notation in a single file that outputs a binary. The binary broadcasts endpoints and returns/transfers the desired data.

Example:

Let's take the Google geocode API endpoint. We'll create a service that given a set of coordinates, returns a google maps image of that location. Let's take this endpoint:

https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA

From that endpoint we'll get a response like this:

endpoint {

}
endpoint {

}
request {
    location: "/google.com"
}
{
   "results" : [
      {
         "address_components" : [
            ...
         ],
         "formatted_address" : "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA",
         "geometry" : {
            "location" : {
               "lat" : 37.4224879,
               "lng" : -122.08422
            },
            ...
         },
         "types" : [ "street_address" ]
      }
   ],
   "status" : "OK"
}

We want to:

  • get a request
  • take the requests parameters
  • pass them to the google api
  • parse the response
  • pass it to the google image api string
  • return that as a response

First let's set up the request endpoint:

server {
    location {
        endpoint /lat-lng-img;
        method get;
        request {
            method get;
            endpoint "https://maps.googleapis.com/maps/api/geocode/json";
            params {
                address params.address;
            }
        }
        return "https://maps.googleapis.com/maps/api/staticmap?center=" + 
            request.results[0].geometry.location.lat + 
            "," + 
            response.results[0].geometry.location.lng + 
            "&zoom=11&size=200x200";
    }
}
"server": {
    "location": {
        "endpoint":"/lat-lng-img",
        "method":"get",
        "request " : [
            {
                "method" : "get",
                "url" : "https://maps.googleapis.com/maps/api/geocode/json",
                "params" : {
                    "address":"params.address"            
                }
            }
        ],
        "return":"'https://maps.googleapis.com/maps/api/staticmap?center=' + 
            request.results[0].geometry.location.lat + 
            ',' + 
            response.results[0].geometry.location.lng + 
            '&zoom=11&size=200x200'"
    }
}
{
    "servers": [
        {
            "location": "/lat-lng-img"
        }
    ]
}

glue's People

Contributors

maxmcd avatar

Watchers

 avatar James Cloos avatar  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.