Git Product home page Git Product logo

api_proxy's Introduction

API Proxy

This is a basic proof of concept to test a read-through cache that proxies API requests to an external service.

Configuration

The file configuration.rb contains the settings for both caching (through VCR) and the proxy configuration -- you can change the target endpoint here and configure any additional HTTP options recognized by the Net::HTTP standard library.

Running

The entry point is implemented as a basic Sinatra app. To run:

$ bundle
$ ruby app.rb

How it Works

The application intercepts all HTTP requests and calculates a signature based on the params and the request body and attempts to match that to an existing cached response (using VCR's built-in recording capabilities). On a cache hit, the stored response is returned, otherwise the request is forwarded to the live endpoint, cached, and the response is returned.

Drawbacks

Requests that have the same signature but expect a different response on subsequent requests currently do not work. For example, a scenario where an item is added to a user's cart:

  1. GET /carts/1 -- Initial request for a user's cart, the response will be cached based on the path.
  2. POST /cart/items -- Request to add an item to the user's cart (with corresponding payload) that will result in a modification to the cart.
  3. GET /carts/1 -- A second request to get the updated cart information. Rather than making a new request and fetching the updated data, this will return the cached response from request #1.

This proxy will not currently work in these situations.

api_proxy's People

Contributors

reagent avatar

Watchers

 avatar  avatar

Forkers

isabella232

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.