danfang / me-api Goto Github PK
View Code? Open in Web Editor NEWAn extensible, personal API with custom integrations
Home Page: http://api.danielfang.org
License: MIT License
An extensible, personal API with custom integrations
Home Page: http://api.danielfang.org
License: MIT License
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:
this.use(path, require("./middleware/" + module))
, maybe something like this.use(path, require(module) || require("./middleware/" + module))
.npm install
. Food for thought.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.
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?
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. ;)
I tried installing the latest me-api-server from npm, but it doesn't seem to have the latest code.
Just a dump of integrations you (and I would like to see).
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.