0.0.5 • Published 11 years ago
api_faker v0.0.5
API Faker
Easy to fake http api.
Features
- Standalone http server to provide fake apis.
- Load
.jsand.jsonfile. - Watch and reload
.jsand.jsonfile. (only tested at OSX) - Proxy mismatch request to another server.
Install
$ npm install -g api_faker
Usage
$ fakeApi -h
Usage: index.coffee [options] <file ...>
Options:
-h, --help output usage information
-V, --version output the version number
-p, --port <port> use the specified port
-r, --proxy <proxy server url> proxy the mismatch request to another server
-v, --verbose verbose output
Examples:
$ fakeApi api.json
$ fakeApi api.js
$ fakeApi api.json api2.json api3.js
$ fakeApi api.json -p 80
$ fakeApi api.json -p 80 -r http://localhost:8080example:
$ fakeApi api.jsapi.js:
module.exports = {
"[GET]/api/users": {
name: "wtf"
},
"[GET]/api/user/:id": function(url, method, params) {
return {
id: params.id
};
}
}use:
$ curl -XGET http://127.0.0.1:8080/api/users
{"name":"wtf"}
$ curl -XGET http://127.0.0.1:8080/api/user/1
{"id":"1"}API file
Support .js and .json file.
.js
module.exports = {
"[GET]/api/users": {
name: "wtf"
},
"[GET]/api/user/:id": function(url, method, params) {
return {
id: params.id
};
}
}.json
{
"[GET]/api/orders": {
"name": "wtf"
}
}pattern
^\[\s*([A-Z]+(\s*,\s*[A-Z]+)*)\s*\]\s*(\/\S*)$base:
[GET]/api/usersmulti methods:
[GET,PUT,POST]/api/usersall methods:
[ALL]/api/userspath variable:
[GET]/api/user/:userId/address/:addressIdWorkflow
- leave all
.jsfiles inlib/folder there - write code with coffee in
src/folder - write test code with coffee in
test/folder - run
npm test, make sure all tests passed - use
npm run compileto compile coffee to js - commit and push to git
To compile and install the repo, use npm run build.