The API definition
So I have got my software stack on a drawing board, next is to make it happen with actual code. RestFul API requests are defined in JSON format:// this is the very 1st API definition, print out something to a remote printer
{
"sid" :"asdfasdf",
"secret" :"13wd23d2323r",
"apiversion" :"2014-01-01",
"service" :"submit",
"parameter" :{
"printerid" :"asdf2323wd2e",
"title" :"xxxxxxx",
"content" :"xxxxxxx",
"contentType" :"PLAINTEXT"
}
}
// Response
{
"jobid" :"xxxx",
"status":"ok", // in progress, fail, ...
"printerid" :"xxxx"
}
Will update the progress soon....
*Edit 2013-12-27
I have been working on this thing during the holiday season. The rough framework code for public API has been setup as follows:Public facing software stack: Centos + Nginx + PHP + mySQL + GearMan
PHP libraries are:
- Luracast Restler - the framework handles RESTful requests
- Idiorm - ActiveRecord library. (When I am too lazy to write real SQL queries)
- Whole bunch of PHP utility functions I wrote in the past.
- Print API data is strictly structured, saved to database as json encoded string.
- RESTful, no state between requests.
- The API will return right after been fired. (before the actual printer output is finished)
- Client Callback url for job status update.
For the actual worker process that handles individual request processing, I might consider something runs on top of libev as daemon. Could be Node.js or Python Twisted, will leave that for later decision.
*Side note: I am thinking about opensource the entire thing on Github, anyone interested?
If someone can help manage the repo, Ill make it happen.
0 komentar:
Posting Komentar