apisdk.js
Build a SDK from API document
Get Started
var api = new APISDK([
'POST /articles',
'GET /articles/{article_id}',
'PUT /articles/{article_id}',
'DELETE /articles/{article_id}'
], {
'host': '/api',
'promise': Promise,
'http': function(params) { console.log(params); }
});
var article_id = 123;
api.articles(article_id).get({ token: 789 });
var inc = 0;
var nextArticle = api.articles(function() { return inc++; });
nextArticle.get();
nextArticle.get();
var asyncParam = new Promise(function(resolve){ setTimeout(resolve, 1000, 123); });
api.articles(asyncParam).get();
Friendly with RESTful API
/**
* GET /users/{user_id}/
* GET /users/{user_id}/orders
* POST /users/{user_id}/orders
* GET /users/{user_id}/orders/{order_id}
* POST /users/{user_id}/orders/{order_id}/payment
* POST /users/{user_id}/orders/{order_id}/rating
* POST /users/{user_id}/orders/{order_id}/cancel
* POST /users/{user_id}/orders/{order_id}/refunding
**/
var currentUserId = 123;
// Create a 'user' object for current user
var user = api.users(currentUserId);
// Get current user profile
user.get();
// Create an 'order' object
var order = user.orders(123);
// Get order information
order.get();
// Post a payment request for this order
order.payment.post();
// Post a rating for this order
order.rating.post();
// Post a order canceling request for this order
order.cancel.post();
// Post refunding request for this order
order.refunding.post();
Run Demo
git clone git@github.com:YanagiEiichi/apisdk
cd apisdk/demo
bower install
cd ..
python -m SimpleHTTPServer
http://localhost:8000/demo/
Install
bower install apisdk
<script src="bower_components/apisdk/apisdk.js"></script>