<commit_before># Carpenter
A powerful declarative tool to automagically generate a JSON-API-compliant REST API from his description.

### Usage
This code creates a REST end-point for `users`.
```js
var mach = require('mach');
var carpenter = require('carpenter');
var db = require('./my-database-handler.js');

carpenter.setConnector(db.connection());

var rest_api = carpenter.declareCollection({
	name: 'users',
	type: {
		id: carpenter.types.id,
		email: carpenter.types.email,
		name: carpenter.type.string.len({max: 30}),
		best_friend: carpenter.types.id
	},
	keys: {
		primary: 'id',
		unique: ['email'],
		foreign: [{
			field: best_friend,
			collection: 'users'
		}]
	},
	actions: carpenter.actions.all
}).exposeAPI();
```
Now the server is capable of handling any of these requests
* `GET /users`
* `GET /users/1`
* `GET /users/1/linked/best_friend`
* `GET /users/1?fields=name`
* `POST /users   {email: '<EMAIL>', name: '<NAME>', best_friend: 1}`
* and almost every other possible request made in the limits of the [JSON API format](http://jsonapi.org/format/)

### License
Good, ol', [MIT license](http://github.com/mattecapu/carpenter/blob/master/LICENSE)<commit_msg>completed the code example<commit_after># Carpenter
A powerful declarative tool to automagically generate a JSON-API-compliant REST API from his description.

### Usage
This code creates a REST end-point for `users`.
```js
var mach = require('mach');
var carpenter = require('carpenter');
var db = require('./my-database-handler.js');

carpenter.setConnector(db.connection());

var rest_api = carpenter.declareCollection({
	name: 'users',
	type: {
		id: carpenter.types.id,
		email: carpenter.types.email,
		name: carpenter.type.string.len({max: 30}),
		best_friend: carpenter.types.id
	},
	keys: {
		primary: 'id',
		unique: ['email'],
		foreign: [{
			field: best_friend,
			collection: 'users'
		}]
	},
	actions: carpenter.actions.all
}).exposeAPI();

var app = mach.stack();

app.map('/api', rest_api);

mach.serve(app, 80);
```
Now the server is capable of handling any of these requests
* `GET /users`
* `GET /users/1`
* `GET /users/1/linked/best_friend`
* `GET /users/1?fields=name`
* `POST /users   {email: '<EMAIL>', name: '<NAME>', best_friend: 1}`
* and almost every other possible request made in the limits of the [JSON API format](http://jsonapi.org/format/)

### License
Good, ol', [MIT license](http://github.com/mattecapu/carpenter/blob/master/LICENSE)
{'fraction_non_alphanumeric': 0.16081632653061226, 'fraction_numerical': 0.005714285714285714, 'mean_word_length': 4.557823129251701, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1102677', 'n_tokens_mistral': 875, 'n_tokens_neox': 814, 'n_words': 231}