Git Product home page Git Product logo

me-api's People

Contributors

creeation avatar danfang avatar dependabot[bot] avatar drei01 avatar lewiscowper avatar magdev avatar marvinroger avatar philipsd6 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

me-api's Issues

How external modules/dependencies would work

Right now, the app looks for specific modules outlined in modules.json in the lib/middleware/ folder. It also pulls all dependency requirements per module from the global package.json.

I was wondering:

  1. If people were to build other npm packages as extensions/alternative modules, how would I allow users to install those? I guess the more specific question is, do I look for global modules as well? E.g. instead of this.use(path, require("./middleware/" + module)), maybe something like this.use(path, require(module) || require("./middleware/" + module)).
  2. Design-wise is it better to remove all the integration dependencies (client libraries) from package.json? That way, the user won't have to install packages for integrations they might not use. Or maybe better yet, there is some way to choose the integrations while they are doing npm install. Food for thought.

404 error on every single route

Hi,

I just installed Me API, and routes all return 404 errors. Looking at the code, I don't understand what happens!

modules.json:

{
    "modules": {
        "medium": {
            "path": "blog",
            "data": {
                "me": "@marvinroger"
            }
        },
        "github": {
            "path": "code",
            "data": {
                "me": "marvinroger"
            }
        }
    },
    "settings": {
        "host": "localhost:3000"
    }
}

me.json:

{
    "name": "Marvin Roger"
}

Logs:

Using standard module: medium on blog                                                                                                                                                                                                      
Using standard module: github on code                                                                                                                                                                                                      
GET / 304 12.854 ms - -                                                                                                                                                                                                                    
GET /blog 404 2.606 ms - 74                                                                                                                                                                                                                
GET /code 404 1.104 ms - 74 

Using node 0.10.25.

Multiple integrations per endpoint.

Let's say you have 3 places people can send you money - Coinbase, Blockchain, and Google Wallet. Ideally, you'd want to have a /pay endpoint that incorporates each of these services.

This might require a complete rethinking of the way integrations are done. Possibly, each integration should return a value instead of returning a response. With promises, you could set up modules.json as path: "/pay", "modules": ["coinbase": {}, "blockchain": {}, "wallet": {}] and perform a for loop on each module, combine the returned values using Promises, and return that aggregate object.

Thoughts?

Refresh data on interval

Right now, the data is cached in memory for DEFAULT_CACHE_MSEC and is refreshed upon a client request if the cached data expired. So, this client will receive its reponse after more time than if data was still cached.

A solution to this would be to cache data at start without expiration date, and to refresh these datas using setInterval. Therefore, only the cached data needs to be served, so the response happens pretty instantly. Another advantage to this is that if the remote API is down, the cached data still exists, so there is always data available from the Me API.

Here is how I would see the implementation, for example using the GitHub middleware:

var request = require('request');
var handleError = require('../util/util');
var cache = require('memory-cache');

var REFRESH_INTERVAL_SEC = 60 * 5; // 5 mins

var Github = {
    source: "github",
    routes: [
        {
            method: "GET",
            path: "",
            refreshInterval: REFRESH_INTERVAL_SEC,
            refresh: function() {
                var url = 'https://api.github.com/users/' + this.me + "/events/public";
                request({ url: url, headers: { 'User-Agent': this.me }}, function(err, response, body) {
                    if (err || response.statusCode != 200) return false;
                    var data = JSON.parse(body);
                    cache.put('github', data); // Store forever
                    console.log('refreshed');
                    return true;
                });
            },
            handler: function(req, res) {
                var cachedResult = cache.get('github');
                if (cachedResult) {
                    return res.json(cachedResult);
                } else { // Happens only if a client requests before refresh method succeeds
                    return res.json({ error: true });
                }
            }
        }
    ]
};

module.exports = Github;

To make this middleware functional, it is a matter of a dozen of lines in lib/routes/me.js.

Data might event be cached on the disk, so that if Me API restarts for some reason and the remote API is down, cache would still be available.

Hope you get the idea, let me know what you think. ;)

Future Integrations

Just a dump of integrations you (and I would like to see).

  1. Statistics logger + database.
    This one excites me a lot. This is a module that doesn't return a response, but aggregates data about your API: who is using it, your most popular content, summaries of various endpoints. Implementation wise, it might change a lot of the way integrations are done currently (e.g. you can't access data cross-integration right now).
  2. Pinterest (unfortunately I think their API is quite disappointing)
  3. Youtube, Flickr, file hosting. More media the people like to promote.
  4. LinkedIn, to provide a standard interface for your professional profile.
  5. Fitbit, Nike band, Jawbone Up.

Instagram and Foursquare don't work with ProxyPass

Instagram can be cheated by setting the callback URI to localhost:3000 and then manually copying out the token from the response, but Foursquare don't like it. This is a problem because I run Apache as my web server and am proxy passing my api.foo.com requests to localhost:3000.

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.