Permalink
Newer
Older
100644 92 lines (70 sloc) 3.22 KB
Feb 3, 2012
3
The goals of this package are to support:
5
- Well-designed APIs (easy to use, scales well, easy to extend, etc)
6
- Simple usage of any API from any programming language. (Its pretty easy already, but we make it even easier)
Feb 3, 2012
7
- Full support for running an API as a service on Linux and Windows operating systems
Apr 10, 2012
8
- Simplicity of development for both API authors and consumers
Dec 28, 2011
10
11
Reasons to use PerfectAPI (Current Feature list)
Dec 28, 2011
12
-------------------------
14
- You want to expose an API using Node.js, or you want to make an existing Node.js module accessible as a remote service API
Apr 10, 2012
15
- You care about performance - [4 times faster than node-restify](http://blog.perfectapi.com/2012/benchmarking-apis-using-perfectapi-vs-express.js-vs-restify.js/)
16
- Easily create a self-hosted server with command-line - `myapp server -p 3002`
Apr 10, 2012
17
- Support for easy configuration via environment variables
18
- Awesomely amazing test page for your users to learn/experiment/test your API, e.g. [amigen api test page](http://services.perfectapi.com:3000/amigen/testapp/)
Feb 3, 2012
19
- Windows and Linux installers (run your API as a true service on your server) - `myapp install myappservicename`
Apr 10, 2012
20
- Automatic validation of required parameters (no need to code boring validation)
21
- Local command-line access to your API
22
- Built-in JSONP interface to your API - that means you can access it using JavaScript from another domain
23
- REST-like interface to your API
24
- Native .NET client to your API - access from .NET without dealing with REST, JSON, WebRequest etc.
25
- Built-in support for max-age and etag server caching - lowers your costs by doing less work
26
27
Is it Perfect?
28
--------------
30
No. See the [FAQ](https://github.com/perfectapi/node-perfectapi/wiki/FAQ)
31
32
Install
33
-------
34
The usual for Node.js stuff
35
36
$ npm install perfectapi
38
or for a global install:
Dec 22, 2011
39
40
$ sudo npm install -g perfectapi
Dec 28, 2011
42
How to include in your API
43
--------------------------
Jan 10, 2012
44
First, create a `perfectapi.json` configuration file. See [Configuration File](node-perfectapi/wiki/perfectapi-config-file-format) for details. Once you have a configuration file, a sample usage is:
Dec 22, 2011
45
46
```
47
#!/usr/bin/env node
48
49
var perfectapi = require('perfectapi');
50
var path = require('path');
51
52
var configPath = path.resolve(__dirname, 'perfectapi.json');
53
var parser = new perfectapi.Parser();
Dec 28, 2011
55
//handle the commands
56
parser.on("mycommand", function(config, callback) {
57
//do mycommand code, putting results into "result" object
59
//after done
60
callback(err, result);
61
});
62
63
parser.on("anothercommand", function(config, callback) {
64
//do anothercommand code, putting results into "result" object
66
//after done
67
callback(err, result);
68
});
69
70
//expose the api
71
module.exports = parser.parse(configPath);
Dec 28, 2011
74
In your `package.json` file, be sure to specify the above file as a "bin", so that the app can be called from the command-line, e.g.
75
76
```
Feb 3, 2012
77
{ "name": "myNodeLib"
78
, "version": "0.0.1"
79
, "description": "My brilliant API"
80
, "main": "./bin/myNodeLib.js"
81
, "bin": "./bin/myNodeLib.js"
82
, "engines": {
83
"node" : ">=0.6.5"
84
}
85
, "dependencies": {
86
"perfectapi": ">=0.0.13"
87
}
Dec 28, 2011
88
}
89
```
90
Thats it.
91
Apr 10, 2012
92
See [the website](http://perfectapi.github.com/node-perfectapi) and [wiki](http://github.com/perfectapi/node-perfectapi/wiki) for more info.