# getapi

> allows to build API's using annotations

Latest version **0.1.0** (published 2012-03-19) · 0 weekly downloads

## Install

```sh
npm install getapi
pnpm add getapi
yarn add getapi
bun add getapi
```

Provides the command `getapi`.

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2012-03-19 |
| First published | 2012-03-19 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | * |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+4 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Eldar Djafarov |
| Maintainers | edjafarov |

## Links

- npm: https://www.npmjs.com/package/getapi
- Repository: https://github.com/edjafarov/getapi
- npm.io page: https://npm.io/package/getapi

## Dependencies (3)

- [express](https://npm.io/package/express.md) 2.5.4
- [optimist](https://npm.io/package/optimist.md) 0.3.1
- [metamodule](https://npm.io/package/metamodule.md) 0.0.2

## Recent versions

- 0.1.0 (latest) — 2012-03-19
- 0.0.1 — 2012-03-19

## README

# getapi - simpliest way to build API
## example
Just add some comments for API to fly

```javascript
/**
* @Route 
* @UrlMapping (url = '/apicall/math/add')
*/
module.exports.add = function(req, res, a, b){
	res.json({result:(parseFloat(a)+parseFloat(b))});
}
```
see more examples:
https://github.com/edjafarov/getapi/blob/master/examples/apis/math.js

## install
```
$npm install getapi -g
```

## use

1) Create you node.js files in some folder.

2) Place comments 

* ```@Route``` - means that this function should handle api call. 
* ```@UrlMapping (url = '[url]')``` allows you to assign url for the function. You can assign url's in usual express manner with named placeholders. But unlike express if you will name one of arguments of a function same as placeholder this argument will be resolved.

```javascript
/**
* @Route 
* @UrlMapping (url = '/apicall/math/pow/:num')
*/
module.exports.pow = function(req, res, a, num){ //num will be resolved to the value of placeholder
	res.json({result:(Math.pow(parseFloat(a),parseFloat(num)))});
}
```

3) ```$ getapi --dir=[path-to-folder] --port=[port]``` 
(if you run ```getapi``` without args default will use current folder and 80 port - aware that in linux to use 80 port you need to be sudo)

4) that's it!

OR

use it programmatically

```javascript
var express = require('express');
var getapi = require('getapi');

var app = express.createServer();

var app = express.createServer(
  express.favicon()
);

app.configure(function() {
	getapi.init(app,"./apis")// initialize routes for API's
    app.set('views', __dirname + "/");
    app.set('view engine', 'ejs');
});

app.get("/",function(req, res){
	res.render('public/homepage.ejs');
});

app.listen(3000);
```

## License

MIT

---
_Source: https://npm.io/package/getapi · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
